[cfe-commits] r69028 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h

Chris Lattner sabre at nondot.org
Mon Apr 13 23:04:17 PDT 2009


Author: lattner
Date: Tue Apr 14 01:04:17 2009
New Revision: 69028

URL: http://llvm.org/viewvc/llvm-project?rev=69028&view=rev
Log:
add a new enum type for linkage, no functionality change.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69028&r1=69027&r2=69028&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 14 01:04:17 2009
@@ -222,8 +222,7 @@
 }
 
 void CodeGenModule::SetGlobalValueAttributes(const Decl *D, 
-                                             bool IsInternal,
-                                             bool IsInline,
+                                             GVALinkage Linkage,
                                              llvm::GlobalValue *GV,
                                              bool ForDefinition) {
   // FIXME: Set up linkage and many other things.  Note, this is a simple 
@@ -246,7 +245,7 @@
       // separate linkage types for this. 
       GV->setLinkage(llvm::Function::ExternalWeakLinkage);
     }
-  } else if (IsInternal) {
+  } else if (Linkage == GVA_Internal) {
     GV->setLinkage(llvm::Function::InternalLinkage);
   } else if (D->hasAttr<DLLExportAttr>()) {
     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
@@ -256,8 +255,9 @@
     } else {
       GV->setLinkage(llvm::Function::DLLExportLinkage);
     }
-  } else if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>() ||
-             IsInline) {
+  } else if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>()) {
+    GV->setLinkage(llvm::Function::WeakAnyLinkage);
+  } else if (Linkage == GVA_Inline || Linkage == GVA_ExternInline) {
     GV->setLinkage(llvm::Function::WeakAnyLinkage);
   }
 
@@ -292,17 +292,29 @@
     F->setCallingConv(llvm::CallingConv::X86_StdCall);
 }
 
+
+static CodeGenModule::GVALinkage 
+GetLinkageForFunctionOrMethodDecl(const Decl *D) {
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+    if (FD->getStorageClass() == FunctionDecl::Static)
+      return CodeGenModule::GVA_Internal;
+    if (FD->isInline()) {
+      if (FD->getStorageClass() == FunctionDecl::Extern)
+        return CodeGenModule::GVA_ExternInline;
+      return CodeGenModule::GVA_Inline;
+    }
+  } else {
+    assert(isa<ObjCMethodDecl>(D));
+    return CodeGenModule::GVA_Internal;
+  }
+  return CodeGenModule::GVA_Normal;
+}
+
 /// SetFunctionAttributesForDefinition - Set function attributes
 /// specific to a function definition.
 void CodeGenModule::SetFunctionAttributesForDefinition(const Decl *D,
                                                        llvm::Function *F) {
-  if (isa<ObjCMethodDecl>(D)) {
-    SetGlobalValueAttributes(D, true, false, F, true);
-  } else {
-    const FunctionDecl *FD = cast<FunctionDecl>(D);
-    SetGlobalValueAttributes(FD, FD->getStorageClass() == FunctionDecl::Static,
-                             FD->isInline(), F, true);
-  }
+  SetGlobalValueAttributes(D, GetLinkageForFunctionOrMethodDecl(D), F, true);
                              
   if (!Features.Exceptions && !Features.ObjCNonFragileABI)
     F->addFnAttr(llvm::Attribute::NoUnwind);  
@@ -325,8 +337,7 @@
                                           llvm::Function *F) {
   SetFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F);
   
-  SetGlobalValueAttributes(FD, FD->getStorageClass() == FunctionDecl::Static,
-                           FD->isInline(), F, false);
+  SetGlobalValueAttributes(FD, GetLinkageForFunctionOrMethodDecl(FD), F, false);
 }
 
 void CodeGenModule::AddUsedGlobal(llvm::GlobalValue *GV) {
@@ -919,7 +930,7 @@
   GA->setName(MangledName);
 
   // Alias should never be internal or inline.
-  SetGlobalValueAttributes(D, false, false, GA, true);
+  SetGlobalValueAttributes(D, GVA_Normal, GA, true);
 }
 
 /// getBuiltinLibFunction - Given a builtin id for a function like

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=69028&r1=69027&r2=69028&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Apr 14 01:04:17 2009
@@ -306,7 +306,13 @@
 
   const char *getMangledName(const NamedDecl *ND);
 
-
+  enum GVALinkage {
+    GVA_Internal,
+    GVA_Inline,
+    GVA_ExternInline,
+    GVA_Normal
+  };
+  
 private:
   llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName,
                                           const llvm::Type *Ty,
@@ -314,11 +320,10 @@
   llvm::Constant *GetOrCreateLLVMGlobal(const char *MangledName,
                                         const llvm::PointerType *PTy,
                                         const VarDecl *D);
-    
+  
   /// SetGlobalValueAttributes - Set attributes for a global decl.
   void SetGlobalValueAttributes(const Decl *D, 
-                                bool IsInternal,
-                                bool IsInline,
+                                GVALinkage Linkage,
                                 llvm::GlobalValue *GV,
                                 bool ForDefinition);
     





More information about the cfe-commits mailing list