CodeGenModule.cpp (195099) | CodeGenModule.cpp (195341) |
---|---|
1//===--- CodeGenModule.cpp - Emit LLVM Code from ASTs for a Module --------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 88 unchanged lines hidden (view full) --- 97} 98 99LangOptions::VisibilityMode 100CodeGenModule::getDeclVisibilityMode(const Decl *D) const { 101 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) 102 if (VD->getStorageClass() == VarDecl::PrivateExtern) 103 return LangOptions::Hidden; 104 | 1//===--- CodeGenModule.cpp - Emit LLVM Code from ASTs for a Module --------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 88 unchanged lines hidden (view full) --- 97} 98 99LangOptions::VisibilityMode 100CodeGenModule::getDeclVisibilityMode(const Decl *D) const { 101 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) 102 if (VD->getStorageClass() == VarDecl::PrivateExtern) 103 return LangOptions::Hidden; 104 |
105 if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>(getContext())) { | 105 if (const VisibilityAttr *attr = D->getAttr |
106 switch (attr->getVisibility()) { 107 default: assert(0 && "Unknown visibility!"); 108 case VisibilityAttr::DefaultVisibility: 109 return LangOptions::Default; 110 case VisibilityAttr::HiddenVisibility: 111 return LangOptions::Hidden; 112 case VisibilityAttr::ProtectedVisibility: 113 return LangOptions::Protected; --- 124 unchanged lines hidden (view full) --- 238 llvm::GlobalValue::AppendingLinkage, Array, 239 "llvm.global.annotations", &TheModule); 240 gv->setSection("llvm.metadata"); 241} 242 243static CodeGenModule::GVALinkage 244GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD, 245 const LangOptions &Features) { | 106 switch (attr->getVisibility()) { 107 default: assert(0 && "Unknown visibility!"); 108 case VisibilityAttr::DefaultVisibility: 109 return LangOptions::Default; 110 case VisibilityAttr::HiddenVisibility: 111 return LangOptions::Hidden; 112 case VisibilityAttr::ProtectedVisibility: 113 return LangOptions::Protected; --- 124 unchanged lines hidden (view full) --- 238 llvm::GlobalValue::AppendingLinkage, Array, 239 "llvm.global.annotations", &TheModule); 240 gv->setSection("llvm.metadata"); 241} 242 243static CodeGenModule::GVALinkage 244GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD, 245 const LangOptions &Features) { |
246 // The kind of external linkage this function will have, if it is not 247 // inline or static. 248 CodeGenModule::GVALinkage External = CodeGenModule::GVA_StrongExternal; 249 if (Context.getLangOptions().CPlusPlus && 250 (FD->getPrimaryTemplate() || FD->getInstantiatedFromMemberFunction()) && 251 !FD->isExplicitSpecialization()) 252 External = CodeGenModule::GVA_TemplateInstantiation; 253 |
|
246 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 247 // C++ member functions defined inside the class are always inline. 248 if (MD->isInline() || !MD->isOutOfLine()) 249 return CodeGenModule::GVA_CXXInline; 250 | 254 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 255 // C++ member functions defined inside the class are always inline. 256 if (MD->isInline() || !MD->isOutOfLine()) 257 return CodeGenModule::GVA_CXXInline; 258 |
251 return CodeGenModule::GVA_StrongExternal; | 259 return External; |
252 } 253 254 // "static" functions get internal linkage. 255 if (FD->getStorageClass() == FunctionDecl::Static) 256 return CodeGenModule::GVA_Internal; 257 258 if (!FD->isInline()) | 260 } 261 262 // "static" functions get internal linkage. 263 if (FD->getStorageClass() == FunctionDecl::Static) 264 return CodeGenModule::GVA_Internal; 265 266 if (!FD->isInline()) |
259 return CodeGenModule::GVA_StrongExternal; | 267 return External; |
260 261 // If the inline function explicitly has the GNU inline attribute on it, or if 262 // this is C89 mode, we use to GNU semantics. 263 if (!Features.C99 && !Features.CPlusPlus) { 264 // extern inline in GNU mode is like C99 inline. 265 if (FD->getStorageClass() == FunctionDecl::Extern) 266 return CodeGenModule::GVA_C99Inline; 267 // Normal inline is a strong symbol. 268 return CodeGenModule::GVA_StrongExternal; 269 } else if (FD->hasActiveGNUInlineAttribute(Context)) { 270 // GCC in C99 mode seems to use a different decision-making 271 // process for extern inline, which factors in previous 272 // declarations. 273 if (FD->isExternGNUInline(Context)) 274 return CodeGenModule::GVA_C99Inline; 275 // Normal inline is a strong symbol. | 268 269 // If the inline function explicitly has the GNU inline attribute on it, or if 270 // this is C89 mode, we use to GNU semantics. 271 if (!Features.C99 && !Features.CPlusPlus) { 272 // extern inline in GNU mode is like C99 inline. 273 if (FD->getStorageClass() == FunctionDecl::Extern) 274 return CodeGenModule::GVA_C99Inline; 275 // Normal inline is a strong symbol. 276 return CodeGenModule::GVA_StrongExternal; 277 } else if (FD->hasActiveGNUInlineAttribute(Context)) { 278 // GCC in C99 mode seems to use a different decision-making 279 // process for extern inline, which factors in previous 280 // declarations. 281 if (FD->isExternGNUInline(Context)) 282 return CodeGenModule::GVA_C99Inline; 283 // Normal inline is a strong symbol. |
276 return CodeGenModule::GVA_StrongExternal; | 284 return External; |
277 } 278 279 // The definition of inline changes based on the language. Note that we 280 // have already handled "static inline" above, with the GVA_Internal case. 281 if (Features.CPlusPlus) // inline and extern inline. 282 return CodeGenModule::GVA_CXXInline; 283 284 assert(Features.C99 && "Must be in C99 mode if not in C89 or C++ mode"); --- 8 unchanged lines hidden (view full) --- 293/// FIXME: This is currently only done for aliases and functions, but not for 294/// variables (these details are set in EmitGlobalVarDefinition for variables). 295void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D, 296 llvm::GlobalValue *GV) { 297 GVALinkage Linkage = GetLinkageForFunction(getContext(), D, Features); 298 299 if (Linkage == GVA_Internal) { 300 GV->setLinkage(llvm::Function::InternalLinkage); | 285 } 286 287 // The definition of inline changes based on the language. Note that we 288 // have already handled "static inline" above, with the GVA_Internal case. 289 if (Features.CPlusPlus) // inline and extern inline. 290 return CodeGenModule::GVA_CXXInline; 291 292 assert(Features.C99 && "Must be in C99 mode if not in C89 or C++ mode"); --- 8 unchanged lines hidden (view full) --- 301/// FIXME: This is currently only done for aliases and functions, but not for 302/// variables (these details are set in EmitGlobalVarDefinition for variables). 303void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D, 304 llvm::GlobalValue *GV) { 305 GVALinkage Linkage = GetLinkageForFunction(getContext(), D, Features); 306 307 if (Linkage == GVA_Internal) { 308 GV->setLinkage(llvm::Function::InternalLinkage); |
301 } else if (D->hasAttr<DLLExportAttr>(getContext())) { | 309 } else if (D->hasAttr |
302 GV->setLinkage(llvm::Function::DLLExportLinkage); | 310 GV->setLinkage(llvm::Function::DLLExportLinkage); |
303 } else if (D->hasAttr<WeakAttr>(getContext())) { | 311 } else if (D->hasAttr |
304 GV->setLinkage(llvm::Function::WeakAnyLinkage); 305 } else if (Linkage == GVA_C99Inline) { 306 // In C99 mode, 'inline' functions are guaranteed to have a strong 307 // definition somewhere else, so we can use available_externally linkage. 308 GV->setLinkage(llvm::Function::AvailableExternallyLinkage); | 312 GV->setLinkage(llvm::Function::WeakAnyLinkage); 313 } else if (Linkage == GVA_C99Inline) { 314 // In C99 mode, 'inline' functions are guaranteed to have a strong 315 // definition somewhere else, so we can use available_externally linkage. 316 GV->setLinkage(llvm::Function::AvailableExternallyLinkage); |
309 } else if (Linkage == GVA_CXXInline) { | 317 } else if (Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) { |
310 // In C++, the compiler has to emit a definition in every translation unit 311 // that references the function. We should use linkonce_odr because 312 // a) if all references in this translation unit are optimized away, we 313 // don't need to codegen it. b) if the function persists, it needs to be 314 // merged with other definitions. c) C++ has the ODR, so we know the 315 // definition is dependable. 316 GV->setLinkage(llvm::Function::LinkOnceODRLinkage); 317 } else { --- 10 unchanged lines hidden (view full) --- 328 llvm::Function *F) { 329 AttributeListType AttributeList; 330 ConstructAttributeList(Info, D, AttributeList); 331 332 F->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), 333 AttributeList.size())); 334 335 // Set the appropriate calling convention for the Function. | 318 // In C++, the compiler has to emit a definition in every translation unit 319 // that references the function. We should use linkonce_odr because 320 // a) if all references in this translation unit are optimized away, we 321 // don't need to codegen it. b) if the function persists, it needs to be 322 // merged with other definitions. c) C++ has the ODR, so we know the 323 // definition is dependable. 324 GV->setLinkage(llvm::Function::LinkOnceODRLinkage); 325 } else { --- 10 unchanged lines hidden (view full) --- 336 llvm::Function *F) { 337 AttributeListType AttributeList; 338 ConstructAttributeList(Info, D, AttributeList); 339 340 F->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), 341 AttributeList.size())); 342 343 // Set the appropriate calling convention for the Function. |
336 if (D->hasAttr<FastCallAttr>(getContext())) | 344 if (D->hasAttr |
337 F->setCallingConv(llvm::CallingConv::X86_FastCall); 338 | 345 F->setCallingConv(llvm::CallingConv::X86_FastCall); 346 |
339 if (D->hasAttr<StdCallAttr>(getContext())) | 347 if (D->hasAttr |
340 F->setCallingConv(llvm::CallingConv::X86_StdCall); 341} 342 343void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, 344 llvm::Function *F) { 345 if (!Features.Exceptions && !Features.ObjCNonFragileABI) 346 F->addFnAttr(llvm::Attribute::NoUnwind); 347 | 348 F->setCallingConv(llvm::CallingConv::X86_StdCall); 349} 350 351void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, 352 llvm::Function *F) { 353 if (!Features.Exceptions && !Features.ObjCNonFragileABI) 354 F->addFnAttr(llvm::Attribute::NoUnwind); 355 |
348 if (D->hasAttr<AlwaysInlineAttr>(getContext())) | 356 if (D->hasAttr |
349 F->addFnAttr(llvm::Attribute::AlwaysInline); 350 | 357 F->addFnAttr(llvm::Attribute::AlwaysInline); 358 |
351 if (D->hasAttr<NoinlineAttr>(getContext())) | 359 if (D->hasAttr |
352 F->addFnAttr(llvm::Attribute::NoInline); 353} 354 355void CodeGenModule::SetCommonAttributes(const Decl *D, 356 llvm::GlobalValue *GV) { 357 setGlobalVisibility(GV, D); 358 | 360 F->addFnAttr(llvm::Attribute::NoInline); 361} 362 363void CodeGenModule::SetCommonAttributes(const Decl *D, 364 llvm::GlobalValue *GV) { 365 setGlobalVisibility(GV, D); 366 |
359 if (D->hasAttr<UsedAttr>(getContext())) | 367 if (D->hasAttr |
360 AddUsedGlobal(GV); 361 | 368 AddUsedGlobal(GV); 369 |
362 if (const SectionAttr *SA = D->getAttr<SectionAttr>(getContext())) | 370 if (const SectionAttr *SA = D->getAttr |
363 GV->setSection(SA->getName()); 364} 365 366void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, 367 llvm::Function *F, 368 const CGFunctionInfo &FI) { 369 SetLLVMFunctionAttributes(D, FI, F); 370 SetLLVMFunctionAttributesForDefinition(D, F); --- 7 unchanged lines hidden (view full) --- 378 llvm::Function *F, 379 bool IsIncompleteFunction) { 380 if (!IsIncompleteFunction) 381 SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F); 382 383 // Only a few attributes are set on declarations; these may later be 384 // overridden by a definition. 385 | 371 GV->setSection(SA->getName()); 372} 373 374void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, 375 llvm::Function *F, 376 const CGFunctionInfo &FI) { 377 SetLLVMFunctionAttributes(D, FI, F); 378 SetLLVMFunctionAttributesForDefinition(D, F); --- 7 unchanged lines hidden (view full) --- 386 llvm::Function *F, 387 bool IsIncompleteFunction) { 388 if (!IsIncompleteFunction) 389 SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F); 390 391 // Only a few attributes are set on declarations; these may later be 392 // overridden by a definition. 393 |
386 if (FD->hasAttr<DLLImportAttr>(getContext())) { | 394 if (FD->hasAttr |
387 F->setLinkage(llvm::Function::DLLImportLinkage); | 395 F->setLinkage(llvm::Function::DLLImportLinkage); |
388 } else if (FD->hasAttr<WeakAttr>(getContext()) || 389 FD->hasAttr<WeakImportAttr>(getContext())) { | 396 } else if (FD->hasAttr 397 FD->hasAttr |
390 // "extern_weak" is overloaded in LLVM; we probably should have 391 // separate linkage types for this. 392 F->setLinkage(llvm::Function::ExternalWeakLinkage); 393 } else { 394 F->setLinkage(llvm::Function::ExternalLinkage); 395 } 396 | 398 // "extern_weak" is overloaded in LLVM; we probably should have 399 // separate linkage types for this. 400 F->setLinkage(llvm::Function::ExternalWeakLinkage); 401 } else { 402 F->setLinkage(llvm::Function::ExternalLinkage); 403 } 404 |
397 if (const SectionAttr *SA = FD->getAttr<SectionAttr>(getContext())) | 405 if (const SectionAttr *SA = FD->getAttr |
398 F->setSection(SA->getName()); 399} 400 401void CodeGenModule::AddUsedGlobal(llvm::GlobalValue *GV) { 402 assert(!GV->isDeclaration() && 403 "Only globals with definition can force usage."); 404 LLVMUsed.push_back(GV); 405} --- 97 unchanged lines hidden (view full) --- 503 llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo) 504 }; 505 return llvm::ConstantStruct::get(Fields, 4, false); 506} 507 508bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { 509 // Never defer when EmitAllDecls is specified or the decl has 510 // attribute used. | 406 F->setSection(SA->getName()); 407} 408 409void CodeGenModule::AddUsedGlobal(llvm::GlobalValue *GV) { 410 assert(!GV->isDeclaration() && 411 "Only globals with definition can force usage."); 412 LLVMUsed.push_back(GV); 413} --- 97 unchanged lines hidden (view full) --- 511 llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo) 512 }; 513 return llvm::ConstantStruct::get(Fields, 4, false); 514} 515 516bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { 517 // Never defer when EmitAllDecls is specified or the decl has 518 // attribute used. |
511 if (Features.EmitAllDecls || Global->hasAttr<UsedAttr>(getContext())) | 519 if (Features.EmitAllDecls || Global->hasAttr |
512 return false; 513 514 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { 515 // Constructors and destructors should never be deferred. | 520 return false; 521 522 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { 523 // Constructors and destructors should never be deferred. |
516 if (FD->hasAttr<ConstructorAttr>(getContext()) || 517 FD->hasAttr<DestructorAttr>(getContext())) | 524 if (FD->hasAttr 525 FD->hasAttr |
518 return false; 519 520 GVALinkage Linkage = GetLinkageForFunction(getContext(), FD, Features); 521 522 // static, static inline, always_inline, and extern inline functions can 523 // always be deferred. Normal inline functions can be deferred in C99/C++. 524 if (Linkage == GVA_Internal || Linkage == GVA_C99Inline || 525 Linkage == GVA_CXXInline) --- 7 unchanged lines hidden (view full) --- 533 return VD->getStorageClass() == VarDecl::Static; 534} 535 536void CodeGenModule::EmitGlobal(GlobalDecl GD) { 537 const ValueDecl *Global = GD.getDecl(); 538 539 // If this is an alias definition (which otherwise looks like a declaration) 540 // emit it now. | 526 return false; 527 528 GVALinkage Linkage = GetLinkageForFunction(getContext(), FD, Features); 529 530 // static, static inline, always_inline, and extern inline functions can 531 // always be deferred. Normal inline functions can be deferred in C99/C++. 532 if (Linkage == GVA_Internal || Linkage == GVA_C99Inline || 533 Linkage == GVA_CXXInline) --- 7 unchanged lines hidden (view full) --- 541 return VD->getStorageClass() == VarDecl::Static; 542} 543 544void CodeGenModule::EmitGlobal(GlobalDecl GD) { 545 const ValueDecl *Global = GD.getDecl(); 546 547 // If this is an alias definition (which otherwise looks like a declaration) 548 // emit it now. |
541 if (Global->hasAttr<AliasAttr>(getContext())) | 549 if (Global->hasAttr |
542 return EmitAliasDefinition(Global); 543 544 // Ignore declarations, they will be emitted on their first use. 545 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { 546 // Forward declarations are emitted lazily on first use. 547 if (!FD->isThisDeclarationADefinition()) 548 return; 549 } else { --- 172 unchanged lines hidden (view full) --- 722 // FIXME: This code is overly simple and should be merged with other global 723 // handling. 724 GV->setConstant(D->getType().isConstant(Context)); 725 726 // FIXME: Merge with other attribute handling code. 727 if (D->getStorageClass() == VarDecl::PrivateExtern) 728 GV->setVisibility(llvm::GlobalValue::HiddenVisibility); 729 | 550 return EmitAliasDefinition(Global); 551 552 // Ignore declarations, they will be emitted on their first use. 553 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { 554 // Forward declarations are emitted lazily on first use. 555 if (!FD->isThisDeclarationADefinition()) 556 return; 557 } else { --- 172 unchanged lines hidden (view full) --- 730 // FIXME: This code is overly simple and should be merged with other global 731 // handling. 732 GV->setConstant(D->getType().isConstant(Context)); 733 734 // FIXME: Merge with other attribute handling code. 735 if (D->getStorageClass() == VarDecl::PrivateExtern) 736 GV->setVisibility(llvm::GlobalValue::HiddenVisibility); 737 |
730 if (D->hasAttr<WeakAttr>(getContext()) || 731 D->hasAttr<WeakImportAttr>(getContext())) | 738 if (D->hasAttr 739 D->hasAttr |
732 GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); 733 734 GV->setThreadLocal(D->isThreadSpecified()); 735 } 736 737 return Entry = GV; 738} 739 --- 103 unchanged lines hidden (view full) --- 843 llvm::Constant *NewPtrForOldDecl = 844 llvm::ConstantExpr::getBitCast(GV, Entry->getType()); 845 Entry->replaceAllUsesWith(NewPtrForOldDecl); 846 847 // Erase the old global, since it is no longer used. 848 cast<llvm::GlobalValue>(Entry)->eraseFromParent(); 849 } 850 | 740 GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); 741 742 GV->setThreadLocal(D->isThreadSpecified()); 743 } 744 745 return Entry = GV; 746} 747 --- 103 unchanged lines hidden (view full) --- 851 llvm::Constant *NewPtrForOldDecl = 852 llvm::ConstantExpr::getBitCast(GV, Entry->getType()); 853 Entry->replaceAllUsesWith(NewPtrForOldDecl); 854 855 // Erase the old global, since it is no longer used. 856 cast<llvm::GlobalValue>(Entry)->eraseFromParent(); 857 } 858 |
851 if (const AnnotateAttr *AA = D->getAttr<AnnotateAttr>(getContext())) { | 859 if (const AnnotateAttr *AA = D->getAttr |
852 SourceManager &SM = Context.getSourceManager(); 853 AddAnnotation(EmitAnnotateAttr(GV, AA, 854 SM.getInstantiationLineNumber(D->getLocation()))); 855 } 856 857 GV->setInitializer(Init); 858 GV->setConstant(D->getType().isConstant(Context)); 859 GV->setAlignment(getContext().getDeclAlignInBytes(D)); 860 861 // Set the llvm linkage type as appropriate. 862 if (D->getStorageClass() == VarDecl::Static) 863 GV->setLinkage(llvm::Function::InternalLinkage); | 860 SourceManager &SM = Context.getSourceManager(); 861 AddAnnotation(EmitAnnotateAttr(GV, AA, 862 SM.getInstantiationLineNumber(D->getLocation()))); 863 } 864 865 GV->setInitializer(Init); 866 GV->setConstant(D->getType().isConstant(Context)); 867 GV->setAlignment(getContext().getDeclAlignInBytes(D)); 868 869 // Set the llvm linkage type as appropriate. 870 if (D->getStorageClass() == VarDecl::Static) 871 GV->setLinkage(llvm::Function::InternalLinkage); |
864 else if (D->hasAttr<DLLImportAttr>(getContext())) | 872 else if (D->hasAttr |
865 GV->setLinkage(llvm::Function::DLLImportLinkage); | 873 GV->setLinkage(llvm::Function::DLLImportLinkage); |
866 else if (D->hasAttr<DLLExportAttr>(getContext())) | 874 else if (D->hasAttr |
867 GV->setLinkage(llvm::Function::DLLExportLinkage); | 875 GV->setLinkage(llvm::Function::DLLExportLinkage); |
868 else if (D->hasAttr<WeakAttr>(getContext())) | 876 else if (D->hasAttr |
869 GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); 870 else if (!CompileOpts.NoCommon && 871 (!D->hasExternalStorage() && !D->getInit())) 872 GV->setLinkage(llvm::GlobalVariable::CommonLinkage); 873 else 874 GV->setLinkage(llvm::GlobalVariable::ExternalLinkage); 875 876 SetCommonAttributes(D, GV); --- 146 unchanged lines hidden (view full) --- 1023 1024 llvm::Function *Fn = cast<llvm::Function>(Entry); 1025 1026 CodeGenFunction(*this).GenerateCode(D, Fn); 1027 1028 SetFunctionDefinitionAttributes(D, Fn); 1029 SetLLVMFunctionAttributesForDefinition(D, Fn); 1030 | 877 GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); 878 else if (!CompileOpts.NoCommon && 879 (!D->hasExternalStorage() && !D->getInit())) 880 GV->setLinkage(llvm::GlobalVariable::CommonLinkage); 881 else 882 GV->setLinkage(llvm::GlobalVariable::ExternalLinkage); 883 884 SetCommonAttributes(D, GV); --- 146 unchanged lines hidden (view full) --- 1031 1032 llvm::Function *Fn = cast<llvm::Function>(Entry); 1033 1034 CodeGenFunction(*this).GenerateCode(D, Fn); 1035 1036 SetFunctionDefinitionAttributes(D, Fn); 1037 SetLLVMFunctionAttributesForDefinition(D, Fn); 1038 |
1031 if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>(getContext())) | 1039 if (const ConstructorAttr *CA = D->getAttr |
1032 AddGlobalCtor(Fn, CA->getPriority()); | 1040 AddGlobalCtor(Fn, CA->getPriority()); |
1033 if (const DestructorAttr *DA = D->getAttr<DestructorAttr>(getContext())) | 1041 if (const DestructorAttr *DA = D->getAttr |
1034 AddGlobalDtor(Fn, DA->getPriority()); 1035} 1036 1037void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) { | 1042 AddGlobalDtor(Fn, DA->getPriority()); 1043} 1044 1045void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) { |
1038 const AliasAttr *AA = D->getAttr<AliasAttr>(getContext()); | 1046 const AliasAttr *AA = D->getAttr |
1039 assert(AA && "Not an alias?"); 1040 1041 const llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); 1042 1043 // Unique the name through the identifier table. 1044 const char *AliaseeName = AA->getAliasee().c_str(); 1045 AliaseeName = getContext().Idents.get(AliaseeName).getName(); 1046 --- 39 unchanged lines hidden (view full) --- 1086 1087 // Now we know that there is no conflict, set the name. 1088 Entry = GA; 1089 GA->setName(MangledName); 1090 1091 // Set attributes which are particular to an alias; this is a 1092 // specialization of the attributes which may be set on a global 1093 // variable/function. | 1047 assert(AA && "Not an alias?"); 1048 1049 const llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); 1050 1051 // Unique the name through the identifier table. 1052 const char *AliaseeName = AA->getAliasee().c_str(); 1053 AliaseeName = getContext().Idents.get(AliaseeName).getName(); 1054 --- 39 unchanged lines hidden (view full) --- 1094 1095 // Now we know that there is no conflict, set the name. 1096 Entry = GA; 1097 GA->setName(MangledName); 1098 1099 // Set attributes which are particular to an alias; this is a 1100 // specialization of the attributes which may be set on a global 1101 // variable/function. |
1094 if (D->hasAttr<DLLExportAttr>(getContext())) { | 1102 if (D->hasAttr |
1095 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1096 // The dllexport attribute is ignored for undefined symbols. | 1103 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1104 // The dllexport attribute is ignored for undefined symbols. |
1097 if (FD->getBody(getContext())) | 1105 if (FD->getBody()) |
1098 GA->setLinkage(llvm::Function::DLLExportLinkage); 1099 } else { 1100 GA->setLinkage(llvm::Function::DLLExportLinkage); 1101 } | 1106 GA->setLinkage(llvm::Function::DLLExportLinkage); 1107 } else { 1108 GA->setLinkage(llvm::Function::DLLExportLinkage); 1109 } |
1102 } else if (D->hasAttr<WeakAttr>(getContext()) || 1103 D->hasAttr<WeakImportAttr>(getContext())) { | 1110 } else if (D->hasAttr 1111 D->hasAttr |
1104 GA->setLinkage(llvm::Function::WeakAnyLinkage); 1105 } 1106 1107 SetCommonAttributes(D, GA); 1108} 1109 1110/// getBuiltinLibFunction - Given a builtin id for a function like 1111/// "__builtin_fabsf", return a Function* for "fabsf". --- 137 unchanged lines hidden (view full) --- 1249 1250 QualType CFTy = getContext().getCFConstantStringType(); 1251 RecordDecl *CFRD = CFTy->getAsRecordType()->getDecl(); 1252 1253 const llvm::StructType *STy = 1254 cast<llvm::StructType>(getTypes().ConvertType(CFTy)); 1255 1256 std::vector<llvm::Constant*> Fields; | 1112 GA->setLinkage(llvm::Function::WeakAnyLinkage); 1113 } 1114 1115 SetCommonAttributes(D, GA); 1116} 1117 1118/// getBuiltinLibFunction - Given a builtin id for a function like 1119/// "__builtin_fabsf", return a Function* for "fabsf". --- 137 unchanged lines hidden (view full) --- 1257 1258 QualType CFTy = getContext().getCFConstantStringType(); 1259 RecordDecl *CFRD = CFTy->getAsRecordType()->getDecl(); 1260 1261 const llvm::StructType *STy = 1262 cast<llvm::StructType>(getTypes().ConvertType(CFTy)); 1263 1264 std::vector<llvm::Constant*> Fields; |
1257 RecordDecl::field_iterator Field = CFRD->field_begin(getContext()); | 1265 RecordDecl::field_iterator Field = CFRD->field_begin(); |
1258 1259 // Class pointer. 1260 FieldDecl *CurField = *Field++; 1261 FieldDecl *NextField = *Field++; 1262 appendFieldAndPadding(*this, Fields, CurField, NextField, 1263 CFConstantStringClassRef, CFRD, STy); 1264 1265 // Flags. --- 153 unchanged lines hidden (view full) --- 1419 return GetAddrOfConstantString(str + '\0', GlobalName); 1420} 1421 1422/// EmitObjCPropertyImplementations - Emit information for synthesized 1423/// properties for an implementation. 1424void CodeGenModule::EmitObjCPropertyImplementations(const 1425 ObjCImplementationDecl *D) { 1426 for (ObjCImplementationDecl::propimpl_iterator | 1266 1267 // Class pointer. 1268 FieldDecl *CurField = *Field++; 1269 FieldDecl *NextField = *Field++; 1270 appendFieldAndPadding(*this, Fields, CurField, NextField, 1271 CFConstantStringClassRef, CFRD, STy); 1272 1273 // Flags. --- 153 unchanged lines hidden (view full) --- 1427 return GetAddrOfConstantString(str + '\0', GlobalName); 1428} 1429 1430/// EmitObjCPropertyImplementations - Emit information for synthesized 1431/// properties for an implementation. 1432void CodeGenModule::EmitObjCPropertyImplementations(const 1433 ObjCImplementationDecl *D) { 1434 for (ObjCImplementationDecl::propimpl_iterator |
1427 i = D->propimpl_begin(getContext()), 1428 e = D->propimpl_end(getContext()); i != e; ++i) { | 1435 i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) { |
1429 ObjCPropertyImplDecl *PID = *i; 1430 1431 // Dynamic is just for type-checking. 1432 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { 1433 ObjCPropertyDecl *PD = PID->getPropertyDecl(); 1434 1435 // Determine which methods need to be implemented, some may have 1436 // been overridden. Note that ::isSynthesized is not the method 1437 // we want, that just indicates if the decl came from a 1438 // property. What we want to know is if the method is defined in 1439 // this implementation. | 1436 ObjCPropertyImplDecl *PID = *i; 1437 1438 // Dynamic is just for type-checking. 1439 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { 1440 ObjCPropertyDecl *PD = PID->getPropertyDecl(); 1441 1442 // Determine which methods need to be implemented, some may have 1443 // been overridden. Note that ::isSynthesized is not the method 1444 // we want, that just indicates if the decl came from a 1445 // property. What we want to know is if the method is defined in 1446 // this implementation. |
1440 if (!D->getInstanceMethod(getContext(), PD->getGetterName())) | 1447 if (!D->getInstanceMethod(PD->getGetterName())) |
1441 CodeGenFunction(*this).GenerateObjCGetter( 1442 const_cast<ObjCImplementationDecl *>(D), PID); 1443 if (!PD->isReadOnly() && | 1448 CodeGenFunction(*this).GenerateObjCGetter( 1449 const_cast<ObjCImplementationDecl *>(D), PID); 1450 if (!PD->isReadOnly() && |
1444 !D->getInstanceMethod(getContext(), PD->getSetterName())) | 1451 !D->getInstanceMethod(PD->getSetterName())) |
1445 CodeGenFunction(*this).GenerateObjCSetter( 1446 const_cast<ObjCImplementationDecl *>(D), PID); 1447 } 1448 } 1449} 1450 1451/// EmitNamespace - Emit all declarations in a namespace. 1452void CodeGenModule::EmitNamespace(const NamespaceDecl *ND) { | 1452 CodeGenFunction(*this).GenerateObjCSetter( 1453 const_cast<ObjCImplementationDecl *>(D), PID); 1454 } 1455 } 1456} 1457 1458/// EmitNamespace - Emit all declarations in a namespace. 1459void CodeGenModule::EmitNamespace(const NamespaceDecl *ND) { |
1453 for (RecordDecl::decl_iterator I = ND->decls_begin(getContext()), 1454 E = ND->decls_end(getContext()); | 1460 for (RecordDecl::decl_iterator I = ND->decls_begin(), E = ND->decls_end(); |
1455 I != E; ++I) 1456 EmitTopLevelDecl(*I); 1457} 1458 1459// EmitLinkageSpec - Emit all declarations in a linkage spec. 1460void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) { 1461 if (LSD->getLanguage() != LinkageSpecDecl::lang_c) { 1462 ErrorUnsupported(LSD, "linkage spec"); 1463 return; 1464 } 1465 | 1461 I != E; ++I) 1462 EmitTopLevelDecl(*I); 1463} 1464 1465// EmitLinkageSpec - Emit all declarations in a linkage spec. 1466void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) { 1467 if (LSD->getLanguage() != LinkageSpecDecl::lang_c) { 1468 ErrorUnsupported(LSD, "linkage spec"); 1469 return; 1470 } 1471 |
1466 for (RecordDecl::decl_iterator I = LSD->decls_begin(getContext()), 1467 E = LSD->decls_end(getContext()); | 1472 for (RecordDecl::decl_iterator I = LSD->decls_begin(), E = LSD->decls_end(); |
1468 I != E; ++I) 1469 EmitTopLevelDecl(*I); 1470} 1471 1472/// EmitTopLevelDecl - Emit code for a single top level declaration. 1473void CodeGenModule::EmitTopLevelDecl(Decl *D) { 1474 // If an error has occurred, stop code generation, but continue 1475 // parsing and semantic analysis (to ensure all warnings and errors 1476 // are emitted). 1477 if (Diags.hasErrorOccurred()) 1478 return; 1479 | 1473 I != E; ++I) 1474 EmitTopLevelDecl(*I); 1475} 1476 1477/// EmitTopLevelDecl - Emit code for a single top level declaration. 1478void CodeGenModule::EmitTopLevelDecl(Decl *D) { 1479 // If an error has occurred, stop code generation, but continue 1480 // parsing and semantic analysis (to ensure all warnings and errors 1481 // are emitted). 1482 if (Diags.hasErrorOccurred()) 1483 return; 1484 |
1485 // Ignore dependent declarations. 1486 if (D->getDeclContext() && D->getDeclContext()->isDependentContext()) 1487 return; 1488 |
|
1480 switch (D->getKind()) { 1481 case Decl::CXXMethod: 1482 case Decl::Function: | 1489 switch (D->getKind()) { 1490 case Decl::CXXMethod: 1491 case Decl::Function: |
1492 // Skip function templates 1493 if (cast<FunctionDecl>(D)->getDescribedFunctionTemplate()) 1494 return; 1495 1496 // Fall through 1497 |
|
1483 case Decl::Var: 1484 EmitGlobal(GlobalDecl(cast<ValueDecl>(D))); 1485 break; 1486 1487 // C++ Decls 1488 case Decl::Namespace: 1489 EmitNamespace(cast<NamespaceDecl>(D)); 1490 break; 1491 // No code generation needed. 1492 case Decl::Using: | 1498 case Decl::Var: 1499 EmitGlobal(GlobalDecl(cast<ValueDecl>(D))); 1500 break; 1501 1502 // C++ Decls 1503 case Decl::Namespace: 1504 EmitNamespace(cast<NamespaceDecl>(D)); 1505 break; 1506 // No code generation needed. 1507 case Decl::Using: |
1508 case Decl::ClassTemplate: 1509 case Decl::FunctionTemplate: |
|
1493 break; 1494 case Decl::CXXConstructor: 1495 EmitCXXConstructors(cast<CXXConstructorDecl>(D)); 1496 break; 1497 case Decl::CXXDestructor: 1498 EmitCXXDestructors(cast<CXXDestructorDecl>(D)); 1499 break; 1500 --- 24 unchanged lines hidden (view full) --- 1525 ObjCImplementationDecl *OMD = cast<ObjCImplementationDecl>(D); 1526 EmitObjCPropertyImplementations(OMD); 1527 Runtime->GenerateClass(OMD); 1528 break; 1529 } 1530 case Decl::ObjCMethod: { 1531 ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(D); 1532 // If this is not a prototype, emit the body. | 1510 break; 1511 case Decl::CXXConstructor: 1512 EmitCXXConstructors(cast<CXXConstructorDecl>(D)); 1513 break; 1514 case Decl::CXXDestructor: 1515 EmitCXXDestructors(cast<CXXDestructorDecl>(D)); 1516 break; 1517 --- 24 unchanged lines hidden (view full) --- 1542 ObjCImplementationDecl *OMD = cast<ObjCImplementationDecl>(D); 1543 EmitObjCPropertyImplementations(OMD); 1544 Runtime->GenerateClass(OMD); 1545 break; 1546 } 1547 case Decl::ObjCMethod: { 1548 ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(D); 1549 // If this is not a prototype, emit the body. |
1533 if (OMD->getBody(getContext())) | 1550 if (OMD->getBody()) |
1534 CodeGenFunction(*this).GenerateObjCMethod(OMD); 1535 break; 1536 } 1537 case Decl::ObjCCompatibleAlias: 1538 // compatibility-alias is a directive and has no code gen. 1539 break; 1540 1541 case Decl::LinkageSpec: --- 23 unchanged lines hidden --- | 1551 CodeGenFunction(*this).GenerateObjCMethod(OMD); 1552 break; 1553 } 1554 case Decl::ObjCCompatibleAlias: 1555 // compatibility-alias is a directive and has no code gen. 1556 break; 1557 1558 case Decl::LinkageSpec: --- 23 unchanged lines hidden --- |