Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CGDecl.cpp - Emit LLVM Code for declarations ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Decl nodes as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 14 | #include "CGDebugInfo.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "CodeGenFunction.h" |
Anders Carlsson | 1a86b33 | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 16 | #include "CodeGenModule.h" |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 17 | #include "CGBlocks.h" |
Daniel Dunbar | de7fb84 | 2008-08-11 05:00:27 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Ken Dyck | bdc601b | 2009-12-22 14:23:30 +0000 | [diff] [blame] | 19 | #include "clang/AST/CharUnits.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Anders Carlsson | 19567ee | 2008-08-25 01:38:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 22 | #include "clang/Basic/SourceManager.h" |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 23 | #include "clang/Basic/TargetInfo.h" |
Chandler Carruth | 06057ce | 2010-06-15 23:19:56 +0000 | [diff] [blame] | 24 | #include "clang/Frontend/CodeGenOptions.h" |
Anders Carlsson | 1a86b33 | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 25 | #include "llvm/GlobalVariable.h" |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 26 | #include "llvm/Intrinsics.h" |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetData.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | #include "llvm/Type.h" |
| 29 | using namespace clang; |
| 30 | using namespace CodeGen; |
| 31 | |
| 32 | |
| 33 | void CodeGenFunction::EmitDecl(const Decl &D) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 34 | switch (D.getKind()) { |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 35 | case Decl::TranslationUnit: |
| 36 | case Decl::Namespace: |
| 37 | case Decl::UnresolvedUsingTypename: |
| 38 | case Decl::ClassTemplateSpecialization: |
| 39 | case Decl::ClassTemplatePartialSpecialization: |
| 40 | case Decl::TemplateTypeParm: |
| 41 | case Decl::UnresolvedUsingValue: |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 42 | case Decl::NonTypeTemplateParm: |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 43 | case Decl::CXXMethod: |
| 44 | case Decl::CXXConstructor: |
| 45 | case Decl::CXXDestructor: |
| 46 | case Decl::CXXConversion: |
| 47 | case Decl::Field: |
Francois Pichet | 41f5e66 | 2010-11-21 06:49:41 +0000 | [diff] [blame] | 48 | case Decl::IndirectField: |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 49 | case Decl::ObjCIvar: |
| 50 | case Decl::ObjCAtDefsField: |
Chris Lattner | aa9fc46 | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 51 | case Decl::ParmVar: |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 52 | case Decl::ImplicitParam: |
| 53 | case Decl::ClassTemplate: |
| 54 | case Decl::FunctionTemplate: |
| 55 | case Decl::TemplateTemplateParm: |
| 56 | case Decl::ObjCMethod: |
| 57 | case Decl::ObjCCategory: |
| 58 | case Decl::ObjCProtocol: |
| 59 | case Decl::ObjCInterface: |
| 60 | case Decl::ObjCCategoryImpl: |
| 61 | case Decl::ObjCImplementation: |
| 62 | case Decl::ObjCProperty: |
| 63 | case Decl::ObjCCompatibleAlias: |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 64 | case Decl::AccessSpec: |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 65 | case Decl::LinkageSpec: |
| 66 | case Decl::ObjCPropertyImpl: |
| 67 | case Decl::ObjCClass: |
| 68 | case Decl::ObjCForwardProtocol: |
| 69 | case Decl::FileScopeAsm: |
| 70 | case Decl::Friend: |
| 71 | case Decl::FriendTemplate: |
| 72 | case Decl::Block: |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 73 | assert(0 && "Declaration not should not be in declstmts!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | case Decl::Function: // void X(); |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 75 | case Decl::Record: // struct/union/class X; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | case Decl::Enum: // enum X; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | case Decl::EnumConstant: // enum ? { X = ? } |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 78 | case Decl::CXXRecord: // struct/union/class X; [C++] |
Daniel Dunbar | fa133a1 | 2009-11-23 00:07:06 +0000 | [diff] [blame] | 79 | case Decl::Using: // using X; [C++] |
| 80 | case Decl::UsingShadow: |
| 81 | case Decl::UsingDirective: // using namespace X; [C++] |
Douglas Gregor | 08688ac | 2010-04-23 02:02:43 +0000 | [diff] [blame] | 82 | case Decl::NamespaceAlias: |
Anders Carlsson | 7b0ca3f | 2009-12-03 17:26:31 +0000 | [diff] [blame] | 83 | case Decl::StaticAssert: // static_assert(X, ""); [C++0x] |
Chris Lattner | 4ae493c | 2011-02-18 02:08:43 +0000 | [diff] [blame] | 84 | case Decl::Label: // __label__ x; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 85 | // None of these decls require codegen support. |
| 86 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Daniel Dunbar | 662174c8 | 2008-08-29 17:28:43 +0000 | [diff] [blame] | 88 | case Decl::Var: { |
| 89 | const VarDecl &VD = cast<VarDecl>(D); |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 90 | assert(VD.isLocalVarDecl() && |
Daniel Dunbar | 662174c8 | 2008-08-29 17:28:43 +0000 | [diff] [blame] | 91 | "Should not see file-scope variables inside a function!"); |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 92 | return EmitVarDecl(VD); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
Anders Carlsson | fcdbb93 | 2008-12-20 21:51:53 +0000 | [diff] [blame] | 95 | case Decl::Typedef: { // typedef int X; |
| 96 | const TypedefDecl &TD = cast<TypedefDecl>(D); |
| 97 | QualType Ty = TD.getUnderlyingType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | |
Anders Carlsson | fcdbb93 | 2008-12-20 21:51:53 +0000 | [diff] [blame] | 99 | if (Ty->isVariablyModifiedType()) |
| 100 | EmitVLASize(Ty); |
| 101 | } |
Daniel Dunbar | 662174c8 | 2008-08-29 17:28:43 +0000 | [diff] [blame] | 102 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | } |
| 104 | |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 105 | /// EmitVarDecl - This method handles emission of any variable declaration |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 106 | /// inside a function, including static vars etc. |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 107 | void CodeGenFunction::EmitVarDecl(const VarDecl &D) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 | switch (D.getStorageClass()) { |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 109 | case SC_None: |
| 110 | case SC_Auto: |
| 111 | case SC_Register: |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 112 | return EmitAutoVarDecl(D); |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 113 | case SC_Static: { |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 114 | llvm::GlobalValue::LinkageTypes Linkage = |
| 115 | llvm::GlobalValue::InternalLinkage; |
| 116 | |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 117 | // If the function definition has some sort of weak linkage, its |
| 118 | // static variables should also be weak so that they get properly |
| 119 | // uniqued. We can't do this in C, though, because there's no |
| 120 | // standard way to agree on which variables are the same (i.e. |
| 121 | // there's no mangling). |
| 122 | if (getContext().getLangOptions().CPlusPlus) |
| 123 | if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage())) |
| 124 | Linkage = CurFn->getLinkage(); |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 125 | |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 126 | return EmitStaticVarDecl(D, Linkage); |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 127 | } |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 128 | case SC_Extern: |
| 129 | case SC_PrivateExtern: |
Lauro Ramos Venancio | fea90b8 | 2008-02-16 22:30:38 +0000 | [diff] [blame] | 130 | // Don't emit it now, allow it to be emitted lazily on its first use. |
| 131 | return; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 132 | } |
Daniel Dunbar | 5466c7b | 2009-04-14 02:25:56 +0000 | [diff] [blame] | 133 | |
| 134 | assert(0 && "Unknown storage class"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 137 | static std::string GetStaticDeclName(CodeGenFunction &CGF, const VarDecl &D, |
| 138 | const char *Separator) { |
| 139 | CodeGenModule &CGM = CGF.CGM; |
John McCall | f746aa6 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 140 | if (CGF.getContext().getLangOptions().CPlusPlus) { |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 141 | llvm::StringRef Name = CGM.getMangledName(&D); |
| 142 | return Name.str(); |
John McCall | f746aa6 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 143 | } |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 144 | |
| 145 | std::string ContextName; |
Fariborz Jahanian | faa5bfc | 2010-11-30 23:07:14 +0000 | [diff] [blame] | 146 | if (!CGF.CurFuncDecl) { |
| 147 | // Better be in a block declared in global scope. |
| 148 | const NamedDecl *ND = cast<NamedDecl>(&D); |
| 149 | const DeclContext *DC = ND->getDeclContext(); |
| 150 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) { |
| 151 | MangleBuffer Name; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 152 | CGM.getBlockMangledName(GlobalDecl(), Name, BD); |
Fariborz Jahanian | faa5bfc | 2010-11-30 23:07:14 +0000 | [diff] [blame] | 153 | ContextName = Name.getString(); |
| 154 | } |
| 155 | else |
| 156 | assert(0 && "Unknown context for block static var decl"); |
| 157 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CGF.CurFuncDecl)) { |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 158 | llvm::StringRef Name = CGM.getMangledName(FD); |
| 159 | ContextName = Name.str(); |
John McCall | f746aa6 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 160 | } else if (isa<ObjCMethodDecl>(CGF.CurFuncDecl)) |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 161 | ContextName = CGF.CurFn->getName(); |
| 162 | else |
Fariborz Jahanian | faa5bfc | 2010-11-30 23:07:14 +0000 | [diff] [blame] | 163 | assert(0 && "Unknown context for static var decl"); |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 164 | |
| 165 | return ContextName + Separator + D.getNameAsString(); |
| 166 | } |
| 167 | |
Daniel Dunbar | 0096acf | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 168 | llvm::GlobalVariable * |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 169 | CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, |
| 170 | const char *Separator, |
| 171 | llvm::GlobalValue::LinkageTypes Linkage) { |
Chris Lattner | 8bcfc5b | 2008-04-06 23:10:54 +0000 | [diff] [blame] | 172 | QualType Ty = D.getType(); |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 173 | assert(Ty->isConstantSizeType() && "VLAs can't be static"); |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 174 | |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 175 | std::string Name = GetStaticDeclName(*this, D, Separator); |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 176 | |
Daniel Dunbar | 0096acf | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 177 | const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); |
Anders Carlsson | 41f8a13 | 2009-09-26 18:16:06 +0000 | [diff] [blame] | 178 | llvm::GlobalVariable *GV = |
| 179 | new llvm::GlobalVariable(CGM.getModule(), LTy, |
| 180 | Ty.isConstant(getContext()), Linkage, |
| 181 | CGM.EmitNullConstant(D.getType()), Name, 0, |
| 182 | D.isThreadSpecified(), Ty.getAddressSpace()); |
Ken Dyck | 8b752f1 | 2010-01-27 17:10:57 +0000 | [diff] [blame] | 183 | GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); |
John McCall | 112c967 | 2010-11-02 21:04:24 +0000 | [diff] [blame] | 184 | if (Linkage != llvm::GlobalValue::InternalLinkage) |
| 185 | GV->setVisibility(CurFn->getVisibility()); |
Anders Carlsson | 41f8a13 | 2009-09-26 18:16:06 +0000 | [diff] [blame] | 186 | return GV; |
Daniel Dunbar | 0096acf | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 187 | } |
| 188 | |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 189 | /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 190 | /// global variable that has already been created for it. If the initializer |
| 191 | /// has a different type than GV does, this may free GV and return a different |
| 192 | /// one. Otherwise it just returns GV. |
| 193 | llvm::GlobalVariable * |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 194 | CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, |
| 195 | llvm::GlobalVariable *GV) { |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 196 | llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this); |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 197 | |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 198 | // If constant emission failed, then this should be a C++ static |
| 199 | // initializer. |
| 200 | if (!Init) { |
| 201 | if (!getContext().getLangOptions().CPlusPlus) |
| 202 | CGM.ErrorUnsupported(D.getInit(), "constant l-value expression"); |
John McCall | 5cd91b5 | 2010-09-08 01:44:27 +0000 | [diff] [blame] | 203 | else if (Builder.GetInsertBlock()) { |
Anders Carlsson | 071c810 | 2010-01-26 04:02:23 +0000 | [diff] [blame] | 204 | // Since we have a static initializer, this global variable can't |
| 205 | // be constant. |
| 206 | GV->setConstant(false); |
John McCall | 5cd91b5 | 2010-09-08 01:44:27 +0000 | [diff] [blame] | 207 | |
John McCall | 3030eb8 | 2010-11-06 09:44:32 +0000 | [diff] [blame] | 208 | EmitCXXGuardedInit(D, GV); |
Anders Carlsson | 071c810 | 2010-01-26 04:02:23 +0000 | [diff] [blame] | 209 | } |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 210 | return GV; |
| 211 | } |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 213 | // The initializer may differ in type from the global. Rewrite |
| 214 | // the global to match the initializer. (We have to do this |
| 215 | // because some types, like unions, can't be completely represented |
| 216 | // in the LLVM type system.) |
John McCall | 9c20fa9 | 2010-09-03 18:58:50 +0000 | [diff] [blame] | 217 | if (GV->getType()->getElementType() != Init->getType()) { |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 218 | llvm::GlobalVariable *OldGV = GV; |
| 219 | |
| 220 | GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), |
| 221 | OldGV->isConstant(), |
| 222 | OldGV->getLinkage(), Init, "", |
John McCall | 112c967 | 2010-11-02 21:04:24 +0000 | [diff] [blame] | 223 | /*InsertBefore*/ OldGV, |
| 224 | D.isThreadSpecified(), |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 225 | D.getType().getAddressSpace()); |
John McCall | 112c967 | 2010-11-02 21:04:24 +0000 | [diff] [blame] | 226 | GV->setVisibility(OldGV->getVisibility()); |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 227 | |
| 228 | // Steal the name of the old global |
| 229 | GV->takeName(OldGV); |
| 230 | |
| 231 | // Replace all uses of the old global with the new global |
| 232 | llvm::Constant *NewPtrForOldDecl = |
| 233 | llvm::ConstantExpr::getBitCast(GV, OldGV->getType()); |
| 234 | OldGV->replaceAllUsesWith(NewPtrForOldDecl); |
| 235 | |
| 236 | // Erase the old global, since it is no longer used. |
| 237 | OldGV->eraseFromParent(); |
| 238 | } |
| 239 | |
| 240 | GV->setInitializer(Init); |
| 241 | return GV; |
| 242 | } |
| 243 | |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 244 | void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D, |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 245 | llvm::GlobalValue::LinkageTypes Linkage) { |
Daniel Dunbar | a985b31 | 2009-02-25 19:45:19 +0000 | [diff] [blame] | 246 | llvm::Value *&DMEntry = LocalDeclMap[&D]; |
| 247 | assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 249 | llvm::GlobalVariable *GV = CreateStaticVarDecl(D, ".", Linkage); |
Daniel Dunbar | a985b31 | 2009-02-25 19:45:19 +0000 | [diff] [blame] | 250 | |
Daniel Dunbar | e5731f8 | 2009-02-25 20:08:33 +0000 | [diff] [blame] | 251 | // Store into LocalDeclMap before generating initializer to handle |
| 252 | // circular references. |
| 253 | DMEntry = GV; |
| 254 | |
John McCall | fe67f3b | 2010-05-04 20:45:42 +0000 | [diff] [blame] | 255 | // We can't have a VLA here, but we can have a pointer to a VLA, |
| 256 | // even though that doesn't really make any sense. |
Eli Friedman | c62aad8 | 2009-04-20 03:54:15 +0000 | [diff] [blame] | 257 | // Make sure to evaluate VLA bounds now so that we have them for later. |
| 258 | if (D.getType()->isVariablyModifiedType()) |
| 259 | EmitVLASize(D.getType()); |
Fariborz Jahanian | 0934914 | 2010-09-07 23:26:17 +0000 | [diff] [blame] | 260 | |
| 261 | // Local static block variables must be treated as globals as they may be |
| 262 | // referenced in their RHS initializer block-literal expresion. |
| 263 | CGM.setStaticLocalDeclAddress(&D, GV); |
Eli Friedman | c62aad8 | 2009-04-20 03:54:15 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 265 | // If this value has an initializer, emit it. |
| 266 | if (D.getInit()) |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 267 | GV = AddInitializerToStaticVarDecl(D, GV); |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 268 | |
Chris Lattner | 0af9523 | 2010-03-10 23:59:59 +0000 | [diff] [blame] | 269 | GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); |
| 270 | |
Daniel Dunbar | 30510ab | 2009-02-12 23:32:54 +0000 | [diff] [blame] | 271 | // FIXME: Merge attribute handling. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 272 | if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) { |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 273 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 274 | llvm::Constant *Ann = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | CGM.EmitAnnotateAttr(GV, AA, |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 276 | SM.getInstantiationLineNumber(D.getLocation())); |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 277 | CGM.AddAnnotation(Ann); |
| 278 | } |
| 279 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 280 | if (const SectionAttr *SA = D.getAttr<SectionAttr>()) |
Daniel Dunbar | 30510ab | 2009-02-12 23:32:54 +0000 | [diff] [blame] | 281 | GV->setSection(SA->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 283 | if (D.hasAttr<UsedAttr>()) |
Daniel Dunbar | 5c61d97 | 2009-02-13 22:08:43 +0000 | [diff] [blame] | 284 | CGM.AddUsedGlobal(GV); |
| 285 | |
Daniel Dunbar | e5731f8 | 2009-02-25 20:08:33 +0000 | [diff] [blame] | 286 | // We may have to cast the constant because of the initializer |
| 287 | // mismatch above. |
| 288 | // |
| 289 | // FIXME: It is really dangerous to store this in the map; if anyone |
| 290 | // RAUW's the GV uses of this constant will be invalid. |
Eli Friedman | 2659052 | 2008-06-08 01:23:18 +0000 | [diff] [blame] | 291 | const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType()); |
Chris Lattner | c0f31fd | 2010-12-02 04:27:29 +0000 | [diff] [blame] | 292 | const llvm::Type *LPtrTy = LTy->getPointerTo(D.getType().getAddressSpace()); |
Owen Anderson | 3c4972d | 2009-07-29 18:54:39 +0000 | [diff] [blame] | 293 | DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 294 | |
| 295 | // Emit global variable debug descriptor for static vars. |
Anders Carlsson | e896d98 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 296 | CGDebugInfo *DI = getDebugInfo(); |
Mike Stump | 4451bd9 | 2009-02-20 00:19:45 +0000 | [diff] [blame] | 297 | if (DI) { |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 298 | DI->setLocation(D.getLocation()); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 299 | DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D); |
| 300 | } |
Anders Carlsson | 1a86b33 | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 303 | unsigned CodeGenFunction::getByRefValueLLVMField(const ValueDecl *VD) const { |
| 304 | assert(ByRefValueInfo.count(VD) && "Did not find value!"); |
| 305 | |
| 306 | return ByRefValueInfo.find(VD)->second.second; |
| 307 | } |
| 308 | |
Fariborz Jahanian | 52a80e1 | 2011-01-26 23:08:27 +0000 | [diff] [blame] | 309 | llvm::Value *CodeGenFunction::BuildBlockByrefAddress(llvm::Value *BaseAddr, |
| 310 | const VarDecl *V) { |
| 311 | llvm::Value *Loc = Builder.CreateStructGEP(BaseAddr, 1, "forwarding"); |
| 312 | Loc = Builder.CreateLoad(Loc); |
| 313 | Loc = Builder.CreateStructGEP(Loc, getByRefValueLLVMField(V), |
| 314 | V->getNameAsString()); |
| 315 | return Loc; |
| 316 | } |
| 317 | |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 318 | /// BuildByRefType - This routine changes a __block variable declared as T x |
| 319 | /// into: |
| 320 | /// |
| 321 | /// struct { |
| 322 | /// void *__isa; |
| 323 | /// void *__forwarding; |
| 324 | /// int32_t __flags; |
| 325 | /// int32_t __size; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 326 | /// void *__copy_helper; // only if needed |
| 327 | /// void *__destroy_helper; // only if needed |
| 328 | /// char padding[X]; // only if needed |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 329 | /// T x; |
| 330 | /// } x |
| 331 | /// |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 332 | const llvm::Type *CodeGenFunction::BuildByRefType(const VarDecl *D) { |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 333 | std::pair<const llvm::Type *, unsigned> &Info = ByRefValueInfo[D]; |
| 334 | if (Info.first) |
| 335 | return Info.first; |
| 336 | |
Anders Carlsson | 9ad5513 | 2009-09-09 02:51:03 +0000 | [diff] [blame] | 337 | QualType Ty = D->getType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 338 | |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 339 | std::vector<const llvm::Type *> Types; |
Anders Carlsson | 3604386 | 2009-09-10 01:32:12 +0000 | [diff] [blame] | 340 | |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 341 | llvm::PATypeHolder ByRefTypeHolder = llvm::OpaqueType::get(getLLVMContext()); |
Anders Carlsson | 3604386 | 2009-09-10 01:32:12 +0000 | [diff] [blame] | 342 | |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 343 | // void *__isa; |
| 344 | Types.push_back(Int8PtrTy); |
| 345 | |
| 346 | // void *__forwarding; |
| 347 | Types.push_back(llvm::PointerType::getUnqual(ByRefTypeHolder)); |
| 348 | |
| 349 | // int32_t __flags; |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 350 | Types.push_back(Int32Ty); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 351 | |
| 352 | // int32_t __size; |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 353 | Types.push_back(Int32Ty); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 354 | |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 355 | bool HasCopyAndDispose = getContext().BlockRequiresCopying(Ty); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 356 | if (HasCopyAndDispose) { |
| 357 | /// void *__copy_helper; |
| 358 | Types.push_back(Int8PtrTy); |
| 359 | |
| 360 | /// void *__destroy_helper; |
| 361 | Types.push_back(Int8PtrTy); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 362 | } |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 363 | |
| 364 | bool Packed = false; |
Ken Dyck | 8b752f1 | 2010-01-27 17:10:57 +0000 | [diff] [blame] | 365 | CharUnits Align = getContext().getDeclAlign(D); |
Ken Dyck | 06f486e | 2011-01-18 02:01:14 +0000 | [diff] [blame] | 366 | if (Align > getContext().toCharUnitsFromBits(Target.getPointerAlign(0))) { |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 367 | // We have to insert padding. |
| 368 | |
| 369 | // The struct above has 2 32-bit integers. |
| 370 | unsigned CurrentOffsetInBytes = 4 * 2; |
| 371 | |
| 372 | // And either 2 or 4 pointers. |
| 373 | CurrentOffsetInBytes += (HasCopyAndDispose ? 4 : 2) * |
| 374 | CGM.getTargetData().getTypeAllocSize(Int8PtrTy); |
| 375 | |
| 376 | // Align the offset. |
| 377 | unsigned AlignedOffsetInBytes = |
Ken Dyck | 8b752f1 | 2010-01-27 17:10:57 +0000 | [diff] [blame] | 378 | llvm::RoundUpToAlignment(CurrentOffsetInBytes, Align.getQuantity()); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 379 | |
| 380 | unsigned NumPaddingBytes = AlignedOffsetInBytes - CurrentOffsetInBytes; |
Anders Carlsson | e0c8822 | 2009-09-13 17:55:13 +0000 | [diff] [blame] | 381 | if (NumPaddingBytes > 0) { |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 382 | const llvm::Type *Ty = llvm::Type::getInt8Ty(getLLVMContext()); |
Mike Stump | 04c688a | 2009-10-21 00:42:55 +0000 | [diff] [blame] | 383 | // FIXME: We need a sema error for alignment larger than the minimum of |
| 384 | // the maximal stack alignmint and the alignment of malloc on the system. |
Anders Carlsson | e0c8822 | 2009-09-13 17:55:13 +0000 | [diff] [blame] | 385 | if (NumPaddingBytes > 1) |
| 386 | Ty = llvm::ArrayType::get(Ty, NumPaddingBytes); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 387 | |
Anders Carlsson | e0c8822 | 2009-09-13 17:55:13 +0000 | [diff] [blame] | 388 | Types.push_back(Ty); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 389 | |
Anders Carlsson | e0c8822 | 2009-09-13 17:55:13 +0000 | [diff] [blame] | 390 | // We want a packed struct. |
| 391 | Packed = true; |
| 392 | } |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // T x; |
Fariborz Jahanian | 469a20d | 2010-09-03 23:07:53 +0000 | [diff] [blame] | 396 | Types.push_back(ConvertTypeForMem(Ty)); |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 397 | |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 398 | const llvm::Type *T = llvm::StructType::get(getLLVMContext(), Types, Packed); |
Anders Carlsson | 3604386 | 2009-09-10 01:32:12 +0000 | [diff] [blame] | 399 | |
| 400 | cast<llvm::OpaqueType>(ByRefTypeHolder.get())->refineAbstractTypeTo(T); |
| 401 | CGM.getModule().addTypeName("struct.__block_byref_" + D->getNameAsString(), |
| 402 | ByRefTypeHolder.get()); |
| 403 | |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 404 | Info.first = ByRefTypeHolder.get(); |
Anders Carlsson | 18be84c | 2009-09-12 02:44:18 +0000 | [diff] [blame] | 405 | |
| 406 | Info.second = Types.size() - 1; |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 407 | |
| 408 | return Info.first; |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 409 | } |
| 410 | |
John McCall | da65ea8 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 411 | namespace { |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 412 | struct CallArrayDtor : EHScopeStack::Cleanup { |
John McCall | da65ea8 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 413 | CallArrayDtor(const CXXDestructorDecl *Dtor, |
| 414 | const ConstantArrayType *Type, |
| 415 | llvm::Value *Loc) |
| 416 | : Dtor(Dtor), Type(Type), Loc(Loc) {} |
| 417 | |
| 418 | const CXXDestructorDecl *Dtor; |
| 419 | const ConstantArrayType *Type; |
| 420 | llvm::Value *Loc; |
| 421 | |
| 422 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
| 423 | QualType BaseElementTy = CGF.getContext().getBaseElementType(Type); |
| 424 | const llvm::Type *BasePtr = CGF.ConvertType(BaseElementTy); |
| 425 | BasePtr = llvm::PointerType::getUnqual(BasePtr); |
| 426 | llvm::Value *BaseAddrPtr = CGF.Builder.CreateBitCast(Loc, BasePtr); |
| 427 | CGF.EmitCXXAggrDestructorCall(Dtor, Type, BaseAddrPtr); |
| 428 | } |
| 429 | }; |
| 430 | |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 431 | struct CallVarDtor : EHScopeStack::Cleanup { |
John McCall | da65ea8 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 432 | CallVarDtor(const CXXDestructorDecl *Dtor, |
| 433 | llvm::Value *NRVOFlag, |
| 434 | llvm::Value *Loc) |
| 435 | : Dtor(Dtor), NRVOFlag(NRVOFlag), Loc(Loc) {} |
| 436 | |
| 437 | const CXXDestructorDecl *Dtor; |
| 438 | llvm::Value *NRVOFlag; |
| 439 | llvm::Value *Loc; |
| 440 | |
| 441 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
| 442 | // Along the exceptions path we always execute the dtor. |
| 443 | bool NRVO = !IsForEH && NRVOFlag; |
| 444 | |
| 445 | llvm::BasicBlock *SkipDtorBB = 0; |
| 446 | if (NRVO) { |
| 447 | // If we exited via NRVO, we skip the destructor call. |
| 448 | llvm::BasicBlock *RunDtorBB = CGF.createBasicBlock("nrvo.unused"); |
| 449 | SkipDtorBB = CGF.createBasicBlock("nrvo.skipdtor"); |
| 450 | llvm::Value *DidNRVO = CGF.Builder.CreateLoad(NRVOFlag, "nrvo.val"); |
| 451 | CGF.Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB); |
| 452 | CGF.EmitBlock(RunDtorBB); |
| 453 | } |
| 454 | |
| 455 | CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, |
| 456 | /*ForVirtualBase=*/false, Loc); |
| 457 | |
| 458 | if (NRVO) CGF.EmitBlock(SkipDtorBB); |
| 459 | } |
| 460 | }; |
| 461 | } |
| 462 | |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 463 | namespace { |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 464 | struct CallStackRestore : EHScopeStack::Cleanup { |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 465 | llvm::Value *Stack; |
| 466 | CallStackRestore(llvm::Value *Stack) : Stack(Stack) {} |
| 467 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
| 468 | llvm::Value *V = CGF.Builder.CreateLoad(Stack, "tmp"); |
| 469 | llvm::Value *F = CGF.CGM.getIntrinsic(llvm::Intrinsic::stackrestore); |
| 470 | CGF.Builder.CreateCall(F, V); |
| 471 | } |
| 472 | }; |
| 473 | |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 474 | struct CallCleanupFunction : EHScopeStack::Cleanup { |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 475 | llvm::Constant *CleanupFn; |
| 476 | const CGFunctionInfo &FnInfo; |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 477 | const VarDecl &Var; |
| 478 | |
| 479 | CallCleanupFunction(llvm::Constant *CleanupFn, const CGFunctionInfo *Info, |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 480 | const VarDecl *Var) |
| 481 | : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {} |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 482 | |
| 483 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 484 | DeclRefExpr DRE(const_cast<VarDecl*>(&Var), Var.getType(), VK_LValue, |
| 485 | SourceLocation()); |
| 486 | // Compute the address of the local variable, in case it's a byref |
| 487 | // or something. |
| 488 | llvm::Value *Addr = CGF.EmitDeclRefLValue(&DRE).getAddress(); |
| 489 | |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 490 | // In some cases, the type of the function argument will be different from |
| 491 | // the type of the pointer. An example of this is |
| 492 | // void f(void* arg); |
| 493 | // __attribute__((cleanup(f))) void *g; |
| 494 | // |
| 495 | // To fix this we insert a bitcast here. |
| 496 | QualType ArgTy = FnInfo.arg_begin()->type; |
| 497 | llvm::Value *Arg = |
| 498 | CGF.Builder.CreateBitCast(Addr, CGF.ConvertType(ArgTy)); |
| 499 | |
| 500 | CallArgList Args; |
| 501 | Args.push_back(std::make_pair(RValue::get(Arg), |
| 502 | CGF.getContext().getPointerType(Var.getType()))); |
| 503 | CGF.EmitCall(FnInfo, CleanupFn, ReturnValueSlot(), Args); |
| 504 | } |
| 505 | }; |
| 506 | |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 507 | struct CallBlockRelease : EHScopeStack::Cleanup { |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 508 | llvm::Value *Addr; |
| 509 | CallBlockRelease(llvm::Value *Addr) : Addr(Addr) {} |
| 510 | |
| 511 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
John McCall | 0d3c985 | 2011-02-18 02:58:31 +0000 | [diff] [blame] | 512 | CGF.BuildBlockRelease(Addr, BLOCK_FIELD_IS_BYREF); |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 513 | } |
| 514 | }; |
| 515 | } |
| 516 | |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 517 | |
| 518 | /// canEmitInitWithFewStoresAfterMemset - Decide whether we can emit the |
| 519 | /// non-zero parts of the specified initializer with equal or fewer than |
| 520 | /// NumStores scalar stores. |
| 521 | static bool canEmitInitWithFewStoresAfterMemset(llvm::Constant *Init, |
| 522 | unsigned &NumStores) { |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 523 | // Zero and Undef never requires any extra stores. |
| 524 | if (isa<llvm::ConstantAggregateZero>(Init) || |
| 525 | isa<llvm::ConstantPointerNull>(Init) || |
| 526 | isa<llvm::UndefValue>(Init)) |
| 527 | return true; |
| 528 | if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) || |
| 529 | isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || |
| 530 | isa<llvm::ConstantExpr>(Init)) |
| 531 | return Init->isNullValue() || NumStores--; |
| 532 | |
| 533 | // See if we can emit each element. |
| 534 | if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) { |
| 535 | for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { |
| 536 | llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i)); |
| 537 | if (!canEmitInitWithFewStoresAfterMemset(Elt, NumStores)) |
| 538 | return false; |
| 539 | } |
| 540 | return true; |
| 541 | } |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 542 | |
| 543 | // Anything else is hard and scary. |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | /// emitStoresForInitAfterMemset - For inits that |
| 548 | /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar |
| 549 | /// stores that would be required. |
| 550 | static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 551 | bool isVolatile, CGBuilderTy &Builder) { |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 552 | // Zero doesn't require any stores. |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 553 | if (isa<llvm::ConstantAggregateZero>(Init) || |
| 554 | isa<llvm::ConstantPointerNull>(Init) || |
| 555 | isa<llvm::UndefValue>(Init)) |
| 556 | return; |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 557 | |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 558 | if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) || |
| 559 | isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || |
| 560 | isa<llvm::ConstantExpr>(Init)) { |
| 561 | if (!Init->isNullValue()) |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 562 | Builder.CreateStore(Init, Loc, isVolatile); |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 563 | return; |
| 564 | } |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 565 | |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 566 | assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) && |
| 567 | "Unknown value type!"); |
| 568 | |
| 569 | for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { |
| 570 | llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i)); |
| 571 | if (Elt->isNullValue()) continue; |
| 572 | |
| 573 | // Otherwise, get a pointer to the element and emit it. |
| 574 | emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 575 | isVolatile, Builder); |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 576 | } |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | |
| 580 | /// shouldUseMemSetPlusStoresToInitialize - Decide whether we should use memset |
| 581 | /// plus some stores to initialize a local variable instead of using a memcpy |
| 582 | /// from a constant global. It is beneficial to use memset if the global is all |
| 583 | /// zeros, or mostly zeros and large. |
| 584 | static bool shouldUseMemSetPlusStoresToInitialize(llvm::Constant *Init, |
| 585 | uint64_t GlobalSize) { |
| 586 | // If a global is all zeros, always use a memset. |
| 587 | if (isa<llvm::ConstantAggregateZero>(Init)) return true; |
| 588 | |
| 589 | |
| 590 | // If a non-zero global is <= 32 bytes, always use a memcpy. If it is large, |
| 591 | // do it if it will require 6 or fewer scalar stores. |
| 592 | // TODO: Should budget depends on the size? Avoiding a large global warrants |
| 593 | // plopping in more stores. |
| 594 | unsigned StoreBudget = 6; |
| 595 | uint64_t SizeLimit = 32; |
| 596 | |
| 597 | return GlobalSize > SizeLimit && |
| 598 | canEmitInitWithFewStoresAfterMemset(Init, StoreBudget); |
| 599 | } |
| 600 | |
| 601 | |
Nick Lewycky | a9de3fa | 2010-12-30 20:21:55 +0000 | [diff] [blame] | 602 | /// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 603 | /// variable declaration with auto, register, or no storage class specifier. |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 604 | /// These turn into simple stack objects, or GlobalValues depending on target. |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 605 | void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) { |
| 606 | AutoVarEmission emission = EmitAutoVarAlloca(D); |
| 607 | EmitAutoVarInit(emission); |
| 608 | EmitAutoVarCleanups(emission); |
| 609 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 610 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 611 | /// EmitAutoVarAlloca - Emit the alloca and debug information for a |
| 612 | /// local variable. Does not emit initalization or destruction. |
| 613 | CodeGenFunction::AutoVarEmission |
| 614 | CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) { |
| 615 | QualType Ty = D.getType(); |
| 616 | |
| 617 | AutoVarEmission emission(D); |
| 618 | |
| 619 | bool isByRef = D.hasAttr<BlocksAttr>(); |
| 620 | emission.IsByRef = isByRef; |
| 621 | |
| 622 | CharUnits alignment = getContext().getDeclAlign(&D); |
| 623 | emission.Alignment = alignment; |
| 624 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 625 | llvm::Value *DeclPtr; |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 626 | if (Ty->isConstantSizeType()) { |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 627 | if (!Target.useGlobalsForAutomaticVariables()) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 628 | bool NRVO = getContext().getLangOptions().ElideConstructors && |
| 629 | D.isNRVOVariable(); |
| 630 | |
| 631 | // If this value is a POD array or struct with a statically |
| 632 | // determinable constant initializer, there are optimizations we |
| 633 | // can do. |
| 634 | // TODO: we can potentially constant-evaluate non-POD structs and |
| 635 | // arrays as long as the initialization is trivial (e.g. if they |
| 636 | // have a non-trivial destructor, but not a non-trivial constructor). |
| 637 | if (D.getInit() && |
| 638 | (Ty->isArrayType() || Ty->isRecordType()) && Ty->isPODType() && |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 639 | D.getInit()->isConstantInitializer(getContext(), false)) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 640 | |
| 641 | // If the variable's a const type, and it's neither an NRVO |
| 642 | // candidate nor a __block variable, emit it as a global instead. |
| 643 | if (CGM.getCodeGenOpts().MergeAllConstants && Ty.isConstQualified() && |
| 644 | !NRVO && !isByRef) { |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 645 | EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 646 | |
| 647 | emission.Address = 0; // signal this condition to later callbacks |
| 648 | assert(emission.wasEmittedAsGlobal()); |
| 649 | return emission; |
Tanya Lattner | 59876c2 | 2009-11-04 01:18:09 +0000 | [diff] [blame] | 650 | } |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 651 | |
| 652 | // Otherwise, tell the initialization code that we're in this case. |
| 653 | emission.IsConstantAggregate = true; |
Tanya Lattner | 59876c2 | 2009-11-04 01:18:09 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 656 | // A normal fixed sized variable becomes an alloca in the entry block, |
| 657 | // unless it's an NRVO variable. |
Eli Friedman | a3460ac | 2009-03-04 04:25:14 +0000 | [diff] [blame] | 658 | const llvm::Type *LTy = ConvertTypeForMem(Ty); |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 659 | |
| 660 | if (NRVO) { |
| 661 | // The named return value optimization: allocate this variable in the |
| 662 | // return slot, so that we can elide the copy when returning this |
| 663 | // variable (C++0x [class.copy]p34). |
| 664 | DeclPtr = ReturnValue; |
Douglas Gregor | 3d91bbc | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 665 | |
| 666 | if (const RecordType *RecordTy = Ty->getAs<RecordType>()) { |
| 667 | if (!cast<CXXRecordDecl>(RecordTy->getDecl())->hasTrivialDestructor()) { |
| 668 | // Create a flag that is used to indicate when the NRVO was applied |
| 669 | // to this variable. Set it to zero to indicate that NRVO was not |
| 670 | // applied. |
Chris Lattner | 4c53dc1 | 2010-12-01 01:47:15 +0000 | [diff] [blame] | 671 | llvm::Value *Zero = Builder.getFalse(); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 672 | llvm::Value *NRVOFlag = CreateTempAlloca(Zero->getType(), "nrvo"); |
Nick Lewycky | a03733b | 2011-02-16 23:59:08 +0000 | [diff] [blame] | 673 | EnsureInsertPoint(); |
Douglas Gregor | 3d91bbc | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 674 | Builder.CreateStore(Zero, NRVOFlag); |
| 675 | |
| 676 | // Record the NRVO flag for this variable. |
| 677 | NRVOFlags[&D] = NRVOFlag; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 678 | emission.NRVOFlag = NRVOFlag; |
Douglas Gregor | 3d91bbc | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 681 | } else { |
| 682 | if (isByRef) |
| 683 | LTy = BuildByRefType(&D); |
| 684 | |
| 685 | llvm::AllocaInst *Alloc = CreateTempAlloca(LTy); |
| 686 | Alloc->setName(D.getNameAsString()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 688 | CharUnits allocaAlignment = alignment; |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 689 | if (isByRef) |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 690 | allocaAlignment = std::max(allocaAlignment, |
Ken Dyck | 06f486e | 2011-01-18 02:01:14 +0000 | [diff] [blame] | 691 | getContext().toCharUnitsFromBits(Target.getPointerAlign(0))); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 692 | Alloc->setAlignment(allocaAlignment.getQuantity()); |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 693 | DeclPtr = Alloc; |
| 694 | } |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 695 | } else { |
| 696 | // Targets that don't support recursion emit locals as globals. |
| 697 | const char *Class = |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 698 | D.getStorageClass() == SC_Register ? ".reg." : ".auto."; |
John McCall | b6bbcc9 | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 699 | DeclPtr = CreateStaticVarDecl(D, Class, |
| 700 | llvm::GlobalValue::InternalLinkage); |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 703 | // FIXME: Can this happen? |
Anders Carlsson | 60d3541 | 2008-12-20 20:46:34 +0000 | [diff] [blame] | 704 | if (Ty->isVariablyModifiedType()) |
| 705 | EmitVLASize(Ty); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 706 | } else { |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 707 | EnsureInsertPoint(); |
| 708 | |
Anders Carlsson | 5ecb1b9 | 2009-02-09 20:41:50 +0000 | [diff] [blame] | 709 | if (!DidCallStackSave) { |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 710 | // Save the stack. |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 711 | llvm::Value *Stack = CreateTempAlloca(Int8PtrTy, "saved_stack"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 713 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave); |
| 714 | llvm::Value *V = Builder.CreateCall(F); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 716 | Builder.CreateStore(V, Stack); |
Anders Carlsson | 5ecb1b9 | 2009-02-09 20:41:50 +0000 | [diff] [blame] | 717 | |
| 718 | DidCallStackSave = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | |
John McCall | d871509 | 2010-07-21 06:13:08 +0000 | [diff] [blame] | 720 | // Push a cleanup block and restore the stack there. |
John McCall | 3ad32c8 | 2011-01-28 08:37:24 +0000 | [diff] [blame] | 721 | // FIXME: in general circumstances, this should be an EH cleanup. |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 722 | EHStack.pushCleanup<CallStackRestore>(NormalCleanup, Stack); |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 725 | // Get the element type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | const llvm::Type *LElemTy = ConvertTypeForMem(Ty); |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 727 | const llvm::Type *LElemPtrTy = LElemTy->getPointerTo(Ty.getAddressSpace()); |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 728 | |
Anders Carlsson | 60d3541 | 2008-12-20 20:46:34 +0000 | [diff] [blame] | 729 | llvm::Value *VLASize = EmitVLASize(Ty); |
Anders Carlsson | 5d46315 | 2008-12-12 07:38:43 +0000 | [diff] [blame] | 730 | |
| 731 | // Allocate memory for the array. |
Anders Carlsson | 41f8a13 | 2009-09-26 18:16:06 +0000 | [diff] [blame] | 732 | llvm::AllocaInst *VLA = |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 733 | Builder.CreateAlloca(llvm::Type::getInt8Ty(getLLVMContext()), VLASize, "vla"); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 734 | VLA->setAlignment(alignment.getQuantity()); |
Anders Carlsson | 41f8a13 | 2009-09-26 18:16:06 +0000 | [diff] [blame] | 735 | |
Eli Friedman | 8f39f5e | 2008-12-20 23:11:59 +0000 | [diff] [blame] | 736 | DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 737 | } |
Eli Friedman | 8f39f5e | 2008-12-20 23:11:59 +0000 | [diff] [blame] | 738 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 739 | llvm::Value *&DMEntry = LocalDeclMap[&D]; |
| 740 | assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); |
| 741 | DMEntry = DeclPtr; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 742 | emission.Address = DeclPtr; |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 743 | |
| 744 | // Emit debug info for local var declaration. |
Anders Carlsson | e896d98 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 745 | if (CGDebugInfo *DI = getDebugInfo()) { |
Daniel Dunbar | 25b6ebf | 2009-07-19 07:03:11 +0000 | [diff] [blame] | 746 | assert(HaveInsertPoint() && "Unexpected unreachable point!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 748 | DI->setLocation(D.getLocation()); |
Sanjiv Gupta | 4381d4b | 2009-05-22 13:54:25 +0000 | [diff] [blame] | 749 | if (Target.useGlobalsForAutomaticVariables()) { |
| 750 | DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 751 | } else |
| 752 | DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 753 | } |
| 754 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 755 | return emission; |
| 756 | } |
| 757 | |
| 758 | /// Determines whether the given __block variable is potentially |
| 759 | /// captured by the given expression. |
| 760 | static bool isCapturedBy(const VarDecl &var, const Expr *e) { |
| 761 | // Skip the most common kinds of expressions that make |
| 762 | // hierarchy-walking expensive. |
| 763 | e = e->IgnoreParenCasts(); |
| 764 | |
| 765 | if (const BlockExpr *be = dyn_cast<BlockExpr>(e)) { |
| 766 | const BlockDecl *block = be->getBlockDecl(); |
| 767 | for (BlockDecl::capture_const_iterator i = block->capture_begin(), |
| 768 | e = block->capture_end(); i != e; ++i) { |
| 769 | if (i->getVariable() == &var) |
| 770 | return true; |
| 771 | } |
| 772 | |
| 773 | // No need to walk into the subexpressions. |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | for (Stmt::const_child_range children = e->children(); children; ++children) |
| 778 | if (isCapturedBy(var, cast<Expr>(*children))) |
| 779 | return true; |
| 780 | |
| 781 | return false; |
| 782 | } |
| 783 | |
| 784 | void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) { |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 785 | assert(emission.Variable && "emission was not valid!"); |
| 786 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 787 | // If this was emitted as a global constant, we're done. |
| 788 | if (emission.wasEmittedAsGlobal()) return; |
| 789 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 790 | const VarDecl &D = *emission.Variable; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 791 | QualType type = D.getType(); |
| 792 | |
Chris Lattner | 1978596 | 2007-07-12 00:39:48 +0000 | [diff] [blame] | 793 | // If this local has an initializer, emit it now. |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 794 | const Expr *Init = D.getInit(); |
| 795 | |
| 796 | // If we are at an unreachable point, we don't need to emit the initializer |
| 797 | // unless it contains a label. |
| 798 | if (!HaveInsertPoint()) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 799 | if (!Init || !ContainsLabel(Init)) return; |
| 800 | EnsureInsertPoint(); |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 801 | } |
| 802 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 803 | CharUnits alignment = emission.Alignment; |
| 804 | |
| 805 | if (emission.IsByRef) { |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 806 | llvm::Value *V; |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 807 | |
| 808 | BlockFieldFlags fieldFlags; |
| 809 | bool fieldNeedsCopyDispose = false; |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 810 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 811 | if (type->isBlockPointerType()) { |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 812 | fieldFlags |= BLOCK_FIELD_IS_BLOCK; |
| 813 | fieldNeedsCopyDispose = true; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 814 | } else if (getContext().isObjCNSObjectType(type) || |
| 815 | type->isObjCObjectPointerType()) { |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 816 | fieldFlags |= BLOCK_FIELD_IS_OBJECT; |
| 817 | fieldNeedsCopyDispose = true; |
| 818 | } else if (getLangOptions().CPlusPlus) { |
| 819 | if (getContext().getBlockVarCopyInits(&D)) |
| 820 | fieldNeedsCopyDispose = true; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 821 | else if (const CXXRecordDecl *record = type->getAsCXXRecordDecl()) |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 822 | fieldNeedsCopyDispose = !record->hasTrivialDestructor(); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 823 | } |
Mike Stump | f4bc312 | 2009-03-07 06:04:31 +0000 | [diff] [blame] | 824 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 825 | llvm::Value *addr = emission.Address; |
| 826 | |
Mike Stump | f4bc312 | 2009-03-07 06:04:31 +0000 | [diff] [blame] | 827 | // FIXME: Someone double check this. |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 828 | if (type.isObjCGCWeak()) |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 829 | fieldFlags |= BLOCK_FIELD_IS_WEAK; |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 830 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 831 | // Initialize the 'isa', which is just 0 or 1. |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 832 | int isa = 0; |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 833 | if (fieldFlags & BLOCK_FIELD_IS_WEAK) |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 834 | isa = 1; |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 835 | V = Builder.CreateIntToPtr(Builder.getInt32(isa), Int8PtrTy, "isa"); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 836 | Builder.CreateStore(V, Builder.CreateStructGEP(addr, 0, "byref.isa")); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 837 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 838 | // Store the address of the variable into its own forwarding pointer. |
| 839 | Builder.CreateStore(addr, |
| 840 | Builder.CreateStructGEP(addr, 1, "byref.forwarding")); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 841 | |
John McCall | 0d3c985 | 2011-02-18 02:58:31 +0000 | [diff] [blame] | 842 | // Blocks ABI: |
| 843 | // c) the flags field is set to either 0 if no helper functions are |
| 844 | // needed or BLOCK_HAS_COPY_DISPOSE if they are, |
| 845 | BlockFlags flags; |
| 846 | if (fieldNeedsCopyDispose) flags |= BLOCK_HAS_COPY_DISPOSE; |
| 847 | Builder.CreateStore(llvm::ConstantInt::get(IntTy, flags.getBitMask()), |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 848 | Builder.CreateStructGEP(addr, 2, "byref.flags")); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 849 | |
Mike Stump | 00470a1 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 850 | const llvm::Type *V1; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 851 | V1 = cast<llvm::PointerType>(addr->getType())->getElementType(); |
John McCall | 0d3c985 | 2011-02-18 02:58:31 +0000 | [diff] [blame] | 852 | V = llvm::ConstantInt::get(IntTy, CGM.GetTargetTypeStoreSize(V1).getQuantity()); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 853 | Builder.CreateStore(V, Builder.CreateStructGEP(addr, 3, "byref.size")); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 854 | |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 855 | if (fieldNeedsCopyDispose) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 856 | llvm::Value *copy_helper = Builder.CreateStructGEP(addr, 4); |
| 857 | Builder.CreateStore(CGM.BuildbyrefCopyHelper(addr->getType(), fieldFlags, |
| 858 | alignment.getQuantity(), &D), |
Mike Stump | ee09422 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 859 | copy_helper); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 860 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 861 | llvm::Value *destroy_helper = Builder.CreateStructGEP(addr, 5); |
| 862 | Builder.CreateStore(CGM.BuildbyrefDestroyHelper(addr->getType(), |
John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 863 | fieldFlags, |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 864 | alignment.getQuantity(), |
| 865 | &D), |
Mike Stump | 1851b68 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 866 | destroy_helper); |
Chris Lattner | 9a19edf | 2007-08-26 05:13:54 +0000 | [diff] [blame] | 867 | } |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 868 | } |
Anders Carlsson | 69c68b7 | 2009-02-07 23:51:38 +0000 | [diff] [blame] | 869 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 870 | if (!Init) return; |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 871 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 872 | // Check whether this is a byref variable that's potentially |
| 873 | // captured and moved by its own initializer. If so, we'll need to |
| 874 | // emit the initializer first, then copy into the variable. |
| 875 | bool capturedByInit = emission.IsByRef && isCapturedBy(D, Init); |
| 876 | |
| 877 | llvm::Value *Loc = |
| 878 | capturedByInit ? emission.Address : emission.getObjectAddress(*this); |
| 879 | |
| 880 | bool isVolatile = type.isVolatileQualified(); |
| 881 | |
| 882 | // If this is a simple aggregate initialization, we can optimize it |
| 883 | // in various ways. |
| 884 | if (emission.IsConstantAggregate) { |
| 885 | assert(!capturedByInit && "constant init contains a capturing block?"); |
| 886 | |
| 887 | llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), type, this); |
| 888 | assert(Init != 0 && "Wasn't a simple constant init?"); |
| 889 | |
| 890 | llvm::Value *SizeVal = |
| 891 | llvm::ConstantInt::get(IntPtrTy, |
| 892 | getContext().getTypeSizeInChars(type).getQuantity()); |
| 893 | |
| 894 | const llvm::Type *BP = Int8PtrTy; |
| 895 | if (Loc->getType() != BP) |
| 896 | Loc = Builder.CreateBitCast(Loc, BP, "tmp"); |
| 897 | |
| 898 | // If the initializer is all or mostly zeros, codegen with memset then do |
| 899 | // a few stores afterward. |
| 900 | if (shouldUseMemSetPlusStoresToInitialize(Init, |
Chris Lattner | 94cd011 | 2010-12-01 02:05:19 +0000 | [diff] [blame] | 901 | CGM.getTargetData().getTypeAllocSize(Init->getType()))) { |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 902 | Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal, |
| 903 | alignment.getQuantity(), isVolatile); |
| 904 | if (!Init->isNullValue()) { |
| 905 | Loc = Builder.CreateBitCast(Loc, Init->getType()->getPointerTo()); |
| 906 | emitStoresForInitAfterMemset(Init, Loc, isVolatile, Builder); |
| 907 | } |
| 908 | } else { |
| 909 | // Otherwise, create a temporary global with the initializer then |
| 910 | // memcpy from the global to the alloca. |
| 911 | std::string Name = GetStaticDeclName(*this, D, "."); |
| 912 | llvm::GlobalVariable *GV = |
Fariborz Jahanian | 20e1c7e | 2010-03-12 21:40:43 +0000 | [diff] [blame] | 913 | new llvm::GlobalVariable(CGM.getModule(), Init->getType(), true, |
| 914 | llvm::GlobalValue::InternalLinkage, |
| 915 | Init, Name, 0, false, 0); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 916 | GV->setAlignment(alignment.getQuantity()); |
Fariborz Jahanian | 20e1c7e | 2010-03-12 21:40:43 +0000 | [diff] [blame] | 917 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 918 | llvm::Value *SrcPtr = GV; |
| 919 | if (SrcPtr->getType() != BP) |
| 920 | SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 921 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 922 | Builder.CreateMemCpy(Loc, SrcPtr, SizeVal, alignment.getQuantity(), |
| 923 | isVolatile); |
Fariborz Jahanian | 20e1c7e | 2010-03-12 21:40:43 +0000 | [diff] [blame] | 924 | } |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 925 | } else if (type->isReferenceType()) { |
| 926 | RValue RV = EmitReferenceBindingToExpr(Init, &D); |
| 927 | if (capturedByInit) Loc = BuildBlockByrefAddress(Loc, &D); |
| 928 | EmitStoreOfScalar(RV.getScalarVal(), Loc, false, alignment.getQuantity(), |
| 929 | type); |
| 930 | } else if (!hasAggregateLLVMType(type)) { |
| 931 | llvm::Value *V = EmitScalarExpr(Init); |
| 932 | if (capturedByInit) Loc = BuildBlockByrefAddress(Loc, &D); |
| 933 | EmitStoreOfScalar(V, Loc, isVolatile, alignment.getQuantity(), type); |
| 934 | } else if (type->isAnyComplexType()) { |
| 935 | ComplexPairTy complex = EmitComplexExpr(Init); |
| 936 | if (capturedByInit) Loc = BuildBlockByrefAddress(Loc, &D); |
| 937 | StoreComplexToAddr(complex, Loc, isVolatile); |
| 938 | } else { |
| 939 | // TODO: how can we delay here if D is captured by its initializer? |
| 940 | EmitAggExpr(Init, AggValueSlot::forAddr(Loc, isVolatile, true, false)); |
Fariborz Jahanian | 20e1c7e | 2010-03-12 21:40:43 +0000 | [diff] [blame] | 941 | } |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 942 | } |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 943 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 944 | void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) { |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 945 | assert(emission.Variable && "emission was not valid!"); |
| 946 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 947 | // If this was emitted as a global constant, we're done. |
| 948 | if (emission.wasEmittedAsGlobal()) return; |
| 949 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 950 | const VarDecl &D = *emission.Variable; |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 951 | |
| 952 | // Handle C++ destruction of variables. |
| 953 | if (getLangOptions().CPlusPlus) { |
| 954 | QualType type = D.getType(); |
| 955 | QualType baseType = getContext().getBaseElementType(type); |
| 956 | if (const RecordType *RT = baseType->getAs<RecordType>()) { |
| 957 | CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(RT->getDecl()); |
Douglas Gregor | b5b30b9 | 2010-05-15 16:39:56 +0000 | [diff] [blame] | 958 | if (!ClassDecl->hasTrivialDestructor()) { |
Douglas Gregor | 3d91bbc | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 959 | // Note: We suppress the destructor call when the corresponding NRVO |
| 960 | // flag has been set. |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 961 | |
| 962 | // Note that for __block variables, we want to destroy the |
| 963 | // original stack object, not the possible forwarded object. |
| 964 | llvm::Value *Loc = emission.getObjectAddress(*this); |
Douglas Gregor | d86c477 | 2010-05-15 06:46:45 +0000 | [diff] [blame] | 965 | |
Douglas Gregor | 1d110e0 | 2010-07-01 14:13:13 +0000 | [diff] [blame] | 966 | const CXXDestructorDecl *D = ClassDecl->getDestructor(); |
Fariborz Jahanian | 6ca0b32 | 2009-08-03 20:20:07 +0000 | [diff] [blame] | 967 | assert(D && "EmitLocalBlockVarDecl - destructor is nul"); |
Fariborz Jahanian | 6fba746 | 2009-10-29 16:22:54 +0000 | [diff] [blame] | 968 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 969 | if (type != baseType) { |
| 970 | const ConstantArrayType *Array = |
| 971 | getContext().getAsConstantArrayType(type); |
| 972 | assert(Array && "types changed without array?"); |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 973 | EHStack.pushCleanup<CallArrayDtor>(NormalAndEHCleanup, |
| 974 | D, Array, Loc); |
Fariborz Jahanian | 7799621 | 2009-11-04 17:57:40 +0000 | [diff] [blame] | 975 | } else { |
John McCall | 1f0fca5 | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 976 | EHStack.pushCleanup<CallVarDtor>(NormalAndEHCleanup, |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 977 | D, emission.NRVOFlag, Loc); |
Fariborz Jahanian | 7799621 | 2009-11-04 17:57:40 +0000 | [diff] [blame] | 978 | } |
Fariborz Jahanian | 6ca0b32 | 2009-08-03 20:20:07 +0000 | [diff] [blame] | 979 | } |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 980 | } |
Fariborz Jahanian | 6ca0b32 | 2009-08-03 20:20:07 +0000 | [diff] [blame] | 981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 983 | // Handle the cleanup attribute. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 984 | if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) { |
Anders Carlsson | 69c68b7 | 2009-02-07 23:51:38 +0000 | [diff] [blame] | 985 | const FunctionDecl *FD = CA->getFunctionDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 987 | llvm::Constant *F = CGM.GetAddrOfFunction(FD); |
Anders Carlsson | 69c68b7 | 2009-02-07 23:51:38 +0000 | [diff] [blame] | 988 | assert(F && "Could not find function!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | |
Anders Carlsson | cabec03 | 2009-04-26 00:34:20 +0000 | [diff] [blame] | 990 | const CGFunctionInfo &Info = CGM.getTypes().getFunctionInfo(FD); |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 991 | EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D); |
Anders Carlsson | 69c68b7 | 2009-02-07 23:51:38 +0000 | [diff] [blame] | 992 | } |
Mike Stump | 797b632 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 993 | |
John McCall | 3469585 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 994 | // If this is a block variable, call _Block_object_destroy |
| 995 | // (on the unforwarded address). |
| 996 | if (emission.IsByRef && |
| 997 | CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) |
| 998 | EHStack.pushCleanup<CallBlockRelease>(NormalAndEHCleanup, emission.Address); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | /// Emit an alloca (or GlobalValue depending on target) |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1002 | /// for the specified parameter and set up LocalDeclMap. |
Devang Patel | 3475380 | 2011-02-16 01:11:51 +0000 | [diff] [blame] | 1003 | void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) { |
Daniel Dunbar | b7ec246 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 1004 | // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl? |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1005 | assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) && |
Daniel Dunbar | b7ec246 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 1006 | "Invalid argument to EmitParmDecl"); |
Chris Lattner | 8bcfc5b | 2008-04-06 23:10:54 +0000 | [diff] [blame] | 1007 | QualType Ty = D.getType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1009 | llvm::Value *DeclPtr; |
Daniel Dunbar | e86bcf0 | 2010-02-08 22:53:07 +0000 | [diff] [blame] | 1010 | // If this is an aggregate or variable sized value, reuse the input pointer. |
| 1011 | if (!Ty->isConstantSizeType() || |
| 1012 | CodeGenFunction::hasAggregateLLVMType(Ty)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1013 | DeclPtr = Arg; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1014 | } else { |
Daniel Dunbar | e86bcf0 | 2010-02-08 22:53:07 +0000 | [diff] [blame] | 1015 | // Otherwise, create a temporary to hold the value. |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 1016 | DeclPtr = CreateMemTemp(Ty, D.getName() + ".addr"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | |
Daniel Dunbar | e86bcf0 | 2010-02-08 22:53:07 +0000 | [diff] [blame] | 1018 | // Store the initial value into the alloca. |
John McCall | 5936e33 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 1019 | EmitStoreOfScalar(Arg, DeclPtr, Ty.isVolatileQualified(), |
| 1020 | getContext().getDeclAlign(&D).getQuantity(), Ty, |
| 1021 | CGM.getTBAAInfo(Ty)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1022 | } |
Daniel Dunbar | e86bcf0 | 2010-02-08 22:53:07 +0000 | [diff] [blame] | 1023 | Arg->setName(D.getName()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1024 | |
| 1025 | llvm::Value *&DMEntry = LocalDeclMap[&D]; |
| 1026 | assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); |
| 1027 | DMEntry = DeclPtr; |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1028 | |
| 1029 | // Emit debug info for param declaration. |
Devang Patel | fee53aa | 2009-10-09 22:06:15 +0000 | [diff] [blame] | 1030 | if (CGDebugInfo *DI = getDebugInfo()) { |
| 1031 | DI->setLocation(D.getLocation()); |
Devang Patel | 3475380 | 2011-02-16 01:11:51 +0000 | [diff] [blame] | 1032 | DI->EmitDeclareOfArgVariable(&D, DeclPtr, Builder); |
Devang Patel | fee53aa | 2009-10-09 22:06:15 +0000 | [diff] [blame] | 1033 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1034 | } |