Add the private linkage.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 15 Jan 2009 20:18:42 +0000 (20:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 15 Jan 2009 20:18:42 +0000 (20:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62279 91177308-0d34-0410-b5e6-96231b3b80d8

72 files changed:
docs/LangRef.html
include/llvm/GlobalValue.h
include/llvm/Module.h
include/llvm/Support/Mangler.h
lib/Analysis/IPA/Andersens.cpp
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/IPA/GlobalsModRef.cpp
lib/Archive/Archive.cpp
lib/AsmParser/LLLexer.cpp
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLToken.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/DwarfWriter.cpp
lib/CodeGen/ELFWriter.cpp
lib/CodeGen/MachOWriter.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/ExecutionEngine/JIT/JIT.cpp
lib/Linker/LinkArchives.cpp
lib/Linker/LinkModules.cpp
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/Alpha/AlphaISelLowering.cpp
lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/CppBackend/CPPBackend.cpp
lib/Target/DarwinTargetAsmInfo.cpp
lib/Target/ELFTargetAsmInfo.cpp
lib/Target/IA64/IA64AsmPrinter.cpp
lib/Target/MSIL/MSILWriter.cpp
lib/Target/Mips/MipsAsmPrinter.cpp
lib/Target/Mips/MipsISelLowering.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
lib/Target/X86/X86Subtarget.cpp
lib/Target/XCore/XCoreAsmPrinter.cpp
lib/Transforms/IPO/ArgumentPromotion.cpp
lib/Transforms/IPO/ConstantMerge.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/IPO/ExtractGV.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/IPConstantPropagation.cpp
lib/Transforms/IPO/Inliner.cpp
lib/Transforms/IPO/Internalize.cpp
lib/Transforms/IPO/MergeFunctions.cpp
lib/Transforms/IPO/StripSymbols.cpp
lib/Transforms/IPO/StructRetPromotion.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/BasicInliner.cpp
lib/Transforms/Utils/InlineCost.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Mangler.cpp
lib/VMCore/Module.cpp
lib/VMCore/Verifier.cpp
test/Assembler/private.ll [new file with mode: 0644]
test/CodeGen/ARM/private.ll [new file with mode: 0644]
test/CodeGen/Alpha/private.ll [new file with mode: 0644]
test/CodeGen/CellSPU/private.ll [new file with mode: 0644]
test/CodeGen/IA64/private.ll [new file with mode: 0644]
test/CodeGen/Mips/private.ll [new file with mode: 0644]
test/CodeGen/PowerPC/private.ll [new file with mode: 0644]
test/CodeGen/SPARC/private.ll [new file with mode: 0644]
test/CodeGen/X86/private.ll [new file with mode: 0644]
test/CodeGen/XCore/private.ll [new file with mode: 0644]
tools/bugpoint/ExtractFunction.cpp
tools/llvm-nm/llvm-nm.cpp

index e097c2a84c5d03083246998be8f9f66ab86541c3..5eef22532621e6f298e0f25f9b3307c5f32b23f9 100644 (file)
@@ -480,13 +480,20 @@ All Global Variables and Functions have one of the following types of linkage:
 
 <dl>
 
-  <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
+  <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
 
-  <dd>Global values with internal linkage are only directly accessible by
+  <dd>Global values with private linkage are only directly accessible by
   objects in the current module.  In particular, linking code into a module with
-  an internal global value may cause the internal to be renamed as necessary to
-  avoid collisions.  Because the symbol is internal to the module, all
-  references can be updated.  This corresponds to the notion of the
+  an private global value may cause the private to be renamed as necessary to
+  avoid collisions.  Because the symbol is private to the module, all
+  references can be updated. This doesn't show up in any symbol table in the
+  object file.
+  </dd>
+
+  <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
+
+  <dd> Similar to private, but the value show as a local symbol (STB_LOCAL in
+  the case of ELF) in the object file. This corresponds to the notion of the
   '<tt>static</tt>' keyword in C.
   </dd>
 
index b0e58d4451c7eb5e6983c37cfcd010ef0d31a35b..8fb5580d0d71099602df1cebcacdc30ad0a53077 100644 (file)
@@ -35,6 +35,7 @@ public:
     WeakLinkage,        ///< Keep one copy of named function when linking (weak)
     AppendingLinkage,   ///< Special purpose, only applies to global arrays
     InternalLinkage,    ///< Rename collisions when linking (static functions)
+    PrivateLinkage,     ///< Like Internal, but omit from symbol table
     DLLImportLinkage,   ///< Function to be imported from DLL
     DLLExportLinkage,   ///< Function to be accessible from DLL
     ExternalWeakLinkage,///< ExternalWeak linkage description
@@ -104,6 +105,10 @@ public:
   bool hasCommonLinkage()     const { return Linkage == CommonLinkage; }
   bool hasAppendingLinkage()  const { return Linkage == AppendingLinkage; }
   bool hasInternalLinkage()   const { return Linkage == InternalLinkage; }
+  bool hasPrivateLinkage()    const { return Linkage == PrivateLinkage; }
+  bool hasLocalLinkage()      const {
+    return Linkage == InternalLinkage || Linkage == PrivateLinkage;
+  }
   bool hasDLLImportLinkage()  const { return Linkage == DLLImportLinkage; }
   bool hasDLLExportLinkage()  const { return Linkage == DLLExportLinkage; }
   bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; }
index af687c84c30a56cbd28247e3f8c46037ef95cf57..b0db50a3799021ea979ef8931062dd78840ea7d9 100644 (file)
@@ -188,7 +188,7 @@ public:
   /// getOrInsertFunction - Look up the specified function in the module symbol
   /// table.  Four possibilities:
   ///   1. If it does not exist, add a prototype for the function and return it.
-  ///   2. If it exists, and has internal linkage, the existing function is
+  ///   2. If it exists, and has a local linkage, the existing function is
   ///      renamed and a new one is inserted.
   ///   3. Otherwise, if the existing function has the correct prototype, return
   ///      the existing function.
index 771c09ee0e56b8421f7fabcf1f64b0b6cb26c279..7820b85095a4c47f0a32e90aab7caf5c46fa0aaf 100644 (file)
@@ -29,6 +29,7 @@ class Mangler {
   /// symbol is marked as not needing this prefix.
   const char *Prefix;
   
+  const char *PrivatePrefix;
   /// UseQuotes - If this is set, the target accepts global names in quotes, 
   /// e.g. "foo bar" is a legal name.  This syntax is used instead of escaping
   /// the space character.  By default, this is false.
@@ -58,7 +59,7 @@ public:
 
   // Mangler ctor - if a prefix is specified, it will be prepended onto all
   // symbols.
-  Mangler(Module &M, const char *Prefix = "");
+  Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "");
 
   /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
   /// strings for assembler labels.
index 38b29fed0b321e24e9166a7c19ac40dd04c6059e..8584d06f7a7b093d98576a7b4c5c6a230f42bee4 100644 (file)
@@ -1084,7 +1084,7 @@ void Andersens::CollectConstraints(Module &M) {
     // At some point we should just add constraints for the escaping functions
     // at solve time, but this slows down solving. For now, we simply mark
     // address taken functions as escaping and treat them as external.
-    if (!F->hasInternalLinkage() || AnalyzeUsesOfFunction(F))
+    if (!F->hasLocalLinkage() || AnalyzeUsesOfFunction(F))
       AddConstraintsForNonInternalLinkage(F);
 
     if (!F->isDeclaration()) {
index 1dfca607d8a64123ab70ab7c07bf0e9bef4b4b0d..c1082a002806b76792679579ffaa18c81a7fb6cd 100644 (file)
@@ -112,7 +112,7 @@ private:
     CallGraphNode *Node = getOrInsertFunction(F);
 
     // If this function has external linkage, anything could call it.
-    if (!F->hasInternalLinkage()) {
+    if (!F->hasLocalLinkage()) {
       ExternalCallingNode->addCalledFunction(CallSite(), Node);
 
       // Found the entry point?
index 99e9d215b0185a75ee0fbe94518c01f003959d26..a795ca675fed0372320f0b7f1358231cd976d1ad 100644 (file)
@@ -164,7 +164,7 @@ Pass *llvm::createGlobalsModRefPass() { return new GlobalsModRef(); }
 void GlobalsModRef::AnalyzeGlobals(Module &M) {
   std::vector<Function*> Readers, Writers;
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (I->hasInternalLinkage()) {
+    if (I->hasLocalLinkage()) {
       if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
         // Remember that we are tracking this global.
         NonAddressTakenGlobals.insert(I);
@@ -175,7 +175,7 @@ void GlobalsModRef::AnalyzeGlobals(Module &M) {
 
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I)
-    if (I->hasInternalLinkage()) {
+    if (I->hasLocalLinkage()) {
       if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
         // Remember that we are tracking this global, and the mod/ref fns
         NonAddressTakenGlobals.insert(I);
@@ -504,7 +504,7 @@ GlobalsModRef::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
   // If we are asking for mod/ref info of a direct call with a pointer to a
   // global we are tracking, return information if we have it.
   if (GlobalValue *GV = dyn_cast<GlobalValue>(P->getUnderlyingObject()))
-    if (GV->hasInternalLinkage())
+    if (GV->hasLocalLinkage())
       if (Function *F = CS.getCalledFunction())
         if (NonAddressTakenGlobals.count(GV))
           if (FunctionRecord *FR = getFunctionInfo(F))
index 776f4dd367ce5f0af7c5b0bfe64e5836143c1017..c6c89d27dbb0ab78592953e2542de3da5ca077eb 100644 (file)
@@ -188,13 +188,13 @@ Archive::~Archive() {
 static void getSymbols(Module*M, std::vector<std::string>& symbols) {
   // Loop over global variables
   for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
-    if (!GI->isDeclaration() && !GI->hasInternalLinkage())
+    if (!GI->isDeclaration() && !GI->hasLocalLinkage())
       if (!GI->getName().empty())
         symbols.push_back(GI->getName());
   
   // Loop over functions
   for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
-    if (!FI->isDeclaration() && !FI->hasInternalLinkage())
+    if (!FI->isDeclaration() && !FI->hasLocalLinkage())
       if (!FI->getName().empty())
         symbols.push_back(FI->getName());
 
index 6a3777dedd8f3819f93f31787d66844b0610eebb..fb491d3278d87bc498eee51d6079ae279541779e 100644 (file)
@@ -453,6 +453,7 @@ lltok::Kind LLLexer::LexIdentifier() {
   KEYWORD(declare); KEYWORD(define);
   KEYWORD(global);  KEYWORD(constant);
 
+  KEYWORD(private);
   KEYWORD(internal);
   KEYWORD(linkonce);
   KEYWORD(weak);
index edfdf1543802a17480cef08d6ccb877f52bc368a..401dc39ca539c977d2abeca0c046c43f8cb23ef8 100644 (file)
@@ -113,6 +113,7 @@ bool LLParser::ParseTopLevelEntities() {
     // optional leading prefixes, the production is:
     // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
     //               OptionalAddrSpace ('constant'|'global') ...
+    case lltok::kw_private:       // OptionalLinkage
     case lltok::kw_internal:      // OptionalLinkage
     case lltok::kw_weak:          // OptionalLinkage
     case lltok::kw_linkonce:      // OptionalLinkage
@@ -375,7 +376,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
 
   if (Linkage != GlobalValue::ExternalLinkage &&
       Linkage != GlobalValue::WeakLinkage &&
-      Linkage != GlobalValue::InternalLinkage)
+      Linkage != GlobalValue::InternalLinkage &&
+      Linkage != GlobalValue::PrivateLinkage)
     return Error(LinkageLoc, "invalid linkage type for alias");
   
   Constant *Aliasee;
@@ -738,6 +740,7 @@ bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
 
 /// ParseOptionalLinkage
 ///   ::= /*empty*/
+///   ::= 'private'
 ///   ::= 'internal'
 ///   ::= 'weak'
 ///   ::= 'linkonce'
@@ -751,6 +754,7 @@ bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
   HasLinkage = false;
   switch (Lex.getKind()) {
   default:                    Res = GlobalValue::ExternalLinkage; return false;
+  case lltok::kw_private:     Res = GlobalValue::PrivateLinkage; break;
   case lltok::kw_internal:    Res = GlobalValue::InternalLinkage; break;
   case lltok::kw_weak:        Res = GlobalValue::WeakLinkage; break;
   case lltok::kw_linkonce:    Res = GlobalValue::LinkOnceLinkage; break;
@@ -2065,6 +2069,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
     if (isDefine)
       return Error(LinkageLoc, "invalid linkage for function definition");
     break;
+  case GlobalValue::PrivateLinkage:
   case GlobalValue::InternalLinkage:
   case GlobalValue::LinkOnceLinkage:
   case GlobalValue::WeakLinkage:
index 75a483fce5c38e916c6efbe858487c51b6d0089e..e3bc908b6e0f4380fafe3c4beb2c1787e2827dda 100644 (file)
@@ -36,7 +36,7 @@ namespace lltok {
     kw_declare, kw_define,
     kw_global,  kw_constant,
 
-    kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
+    kw_private, kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
     kw_dllexport, kw_common, kw_default, kw_hidden, kw_protected,
     kw_extern_weak,
     kw_external, kw_thread_local,
index 2d994d4b13d03d71bab25d111a0d0e2bfacec3b5..87700284c483dae87725c9d5310ff237e1dd003f 100644 (file)
@@ -67,6 +67,7 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
   case 6: return GlobalValue::DLLExportLinkage;
   case 7: return GlobalValue::ExternalWeakLinkage;
   case 8: return GlobalValue::CommonLinkage;
+  case 9: return GlobalValue::PrivateLinkage;
   }
 }
 
index 81a1a3799698e6186425d99eb155b0459cfd1e75..da400a736073f35be5138734982a63487ba0ae5c 100644 (file)
@@ -284,6 +284,7 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
   case GlobalValue::DLLExportLinkage:    return 6;
   case GlobalValue::ExternalWeakLinkage: return 7;
   case GlobalValue::CommonLinkage:       return 8;
+  case GlobalValue::PrivateLinkage:      return 9;
   }
 }
 
index 6627543a85695a6bad039330a63fbd6660126e55..5b665a0c22139c80e5d613be1e4991e2610fc9cc 100644 (file)
@@ -139,7 +139,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
 }
 
 bool AsmPrinter::doInitialization(Module &M) {
-  Mang = new Mangler(M, TAI->getGlobalPrefix());
+  Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix());
   
   GCModuleInfo *MI = getAnalysisToUpdate<GCModuleInfo>();
   assert(MI && "AsmPrinter didn't require GCModuleInfo?");
@@ -199,7 +199,7 @@ bool AsmPrinter::doFinalization(Module &M) {
         O << "\t.globl\t" << Name << '\n';
       else if (I->hasWeakLinkage())
         O << TAI->getWeakRefDirective() << Name << '\n';
-      else if (!I->hasInternalLinkage())
+      else if (!I->hasLocalLinkage())
         assert(0 && "Invalid alias linkage");
 
       printVisibility(Name, I->getVisibility());
index 09d169b6f338b04731c6ec45a36c0d6f8b5e537c..02f27d181a9e4f5b82c7fab576e6d0fdd1bcc9f4 100644 (file)
@@ -3272,7 +3272,8 @@ private:
     // Externally visible entry into the functions eh frame info.
     // If the corresponding function is static, this should not be
     // externally visible.
-    if (linkage != Function::InternalLinkage) {
+    if (linkage != Function::InternalLinkage &&
+       linkage != Function::PrivateLinkage) {
       if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
         O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
     }
index 5d2fca134e67de1683842d2995e03d3ebc1958a6..b698178d780db6007b36cf325c3548f65d46ca05 100644 (file)
@@ -174,6 +174,8 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) {
   case GlobalValue::WeakLinkage:
     FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK);
     break;
+  case GlobalValue::PrivateLinkage:
+    assert (0 && "PrivateLinkage should not be in the symbol table.");
   case GlobalValue::InternalLinkage:
     FnSym.SetBind(ELFWriter::ELFSym::STB_LOCAL);
     break;
@@ -329,7 +331,8 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) {
 
     // Set the idx of the .bss section
     BSSSym.SectionIdx = BSSSection.SectionIdx;
-    SymbolTable.push_back(BSSSym);
+    if (!GV->hasPrivateLinkage())
+      SymbolTable.push_back(BSSSym);
 
     // Reserve space in the .bss section for this symbol.
     BSSSection.Size += Size;
index ae1f0d4b045695843071598581ae29a04c750d7f..ef37db8ac9daaf501720384bc896a1342142c94f 100644 (file)
@@ -371,7 +371,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
       SecDataOut.outbyte(0);
   }
   // Globals without external linkage apparently do not go in the symbol table.
-  if (GV->getLinkage() != GlobalValue::InternalLinkage) {
+  if (!GV->hasLocalLinkage()) {
     MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TM);
     Sym.n_value = Sec->size;
     SymbolTable.push_back(Sym);
@@ -959,6 +959,9 @@ MachOSym::MachOSym(const GlobalValue *gv, std::string name, uint8_t sect,
     GVName = TAI->getGlobalPrefix() + name;
     n_type |= GV->hasHiddenVisibility() ? N_PEXT : N_EXT;
     break;
+  case GlobalValue::PrivateLinkage:
+    GVName = TAI->getPrivateGlobalPrefix() + name;
+    break;
   case GlobalValue::InternalLinkage:
     GVName = TAI->getGlobalPrefix() + name;
     break;
index 60a4f61d2561910c79aa45bf73697ea22e00bf51..49b7ad80a28faf3bd2b41a8852813d6fa4ebc6af 100644 (file)
@@ -4276,7 +4276,7 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
     // Check for well-known libc/libm calls.  If the function is internal, it
     // can't be a library call.
     unsigned NameLen = F->getNameLen();
-    if (!F->hasInternalLinkage() && NameLen) {
+    if (!F->hasLocalLinkage() && NameLen) {
       const char *NameStr = F->getNameStart();
       if (NameStr[0] == 'c' &&
           ((NameLen == 8 && !strcmp(NameStr, "copysign")) ||
index 9c7592841d463fdfecbd8360aa089343e1b7981a..a1fbdd281241335085e8878176b1d8a8021bc986 100644 (file)
@@ -249,7 +249,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module *module, bool isDt
  // an old-style (llvmgcc3) static ctor with __main linked in and in use.  If
  // this is the case, don't execute any of the global ctors, __main will do
  // it.
- if (!GV || GV->isDeclaration() || GV->hasInternalLinkage()) return;
+ if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
  
  // Should be an array of '{ int, void ()* }' structs.  The first value is
  // the init priority, which we ignore.
@@ -893,7 +893,7 @@ void ExecutionEngine::emitGlobals() {
       for (Module::const_global_iterator I = M.global_begin(),
            E = M.global_end(); I != E; ++I) {
         const GlobalValue *GV = I;
-        if (GV->hasInternalLinkage() || GV->isDeclaration() ||
+        if (GV->hasLocalLinkage() || GV->isDeclaration() ||
             GV->hasAppendingLinkage() || !GV->hasName())
           continue;// Ignore external globals and globals with internal linkage.
           
index 1db36627005b2523469b6e83c69ab916ba998296..dc502c1e8be1381c1557f61c2c09551056332a46 100644 (file)
@@ -554,7 +554,7 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
     addGlobalMapping(GV, Ptr);
     }
   } else {
-    if (isGVCompilationDisabled() && !GV->hasInternalLinkage()) {
+    if (isGVCompilationDisabled() && !GV->hasLocalLinkage()) {
       cerr << "Compilation of non-internal GlobalValue is disabled!\n";
       abort();
     }
index 6cab77c60106b68f27807c012068e05b6e932a9b..551cc8c390d86594de9813ec264ef9b488b5a5b7 100644 (file)
@@ -50,7 +50,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
     if (I->hasName()) {
       if (I->isDeclaration())
         UndefinedSymbols.insert(I->getName());
-      else if (!I->hasInternalLinkage()) {
+      else if (!I->hasLocalLinkage()) {
         assert(!I->hasDLLImportLinkage()
                && "Found dllimported non-external symbol!");
         DefinedSymbols.insert(I->getName());
@@ -62,7 +62,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
     if (I->hasName()) {
       if (I->isDeclaration())
         UndefinedSymbols.insert(I->getName());
-      else if (!I->hasInternalLinkage()) {
+      else if (!I->hasLocalLinkage()) {
         assert(!I->hasDLLImportLinkage()
                && "Found dllimported non-external symbol!");
         DefinedSymbols.insert(I->getName());
index b8b36ad475068a828b6c5066ab160ca5b5bcc48f..001db21555ccddc841f0ad1982afc4838c7120a9 100644 (file)
@@ -1,4 +1,4 @@
-//===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
+ //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -415,7 +415,7 @@ static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
 
   // If there is a conflict, rename the conflict.
   if (GlobalValue *ConflictGV = cast_or_null<GlobalValue>(ST.lookup(Name))) {
-    assert(ConflictGV->hasInternalLinkage() &&
+    assert(ConflictGV->hasLocalLinkage() &&
            "Not conflicting with a static global, should link instead!");
     GV->takeName(ConflictGV);
     ConflictGV->setName(Name);    // This will cause ConflictGV to get renamed
@@ -444,7 +444,7 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
 static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
                              GlobalValue::LinkageTypes &LT, bool &LinkFromSrc,
                              std::string *Err) {
-  assert((!Dest || !Src->hasInternalLinkage()) &&
+  assert((!Dest || !Src->hasLocalLinkage()) &&
          "If Src has internal linkage, Dest shouldn't be set!");
   if (!Dest) {
     // Linking something to nothing.
@@ -536,13 +536,13 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
 
     // Check to see if may have to link the global with the global, alias or
     // function.
-    if (SGV->hasName() && !SGV->hasInternalLinkage())
+    if (SGV->hasName() && !SGV->hasLocalLinkage())
       DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameStart(),
                                                         SGV->getNameEnd()));
     
     // If we found a global with the same name in the dest module, but it has
     // internal linkage, we are really not doing any linkage here.
-    if (DGV && DGV->hasInternalLinkage())
+    if (DGV && DGV->hasLocalLinkage())
       DGV = 0;
     
     // If types don't agree due to opaque types, try to resolve them.
@@ -573,7 +573,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
       // If the LLVM runtime renamed the global, but it is an externally visible
       // symbol, DGV must be an existing global with internal linkage.  Rename
       // it.
-      if (!NewDGV->hasInternalLinkage() && NewDGV->getName() != SGV->getName())
+      if (!NewDGV->hasLocalLinkage() && NewDGV->getName() != SGV->getName())
         ForceRenaming(NewDGV, SGV->getName());
 
       // Make sure to remember this mapping.
@@ -643,7 +643,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
 
       // If the symbol table renamed the global, but it is an externally visible
       // symbol, DGV must be an existing global with internal linkage.  Rename.
-      if (NewDGV->getName() != SGV->getName() && !NewDGV->hasInternalLinkage())
+      if (NewDGV->getName() != SGV->getName() && !NewDGV->hasLocalLinkage())
         ForceRenaming(NewDGV, SGV->getName());
       
       // Inherit const as appropriate.
@@ -687,10 +687,12 @@ CalculateAliasLinkage(const GlobalValue *SGV, const GlobalValue *DGV) {
     return GlobalValue::ExternalLinkage;
   else if (SGV->hasWeakLinkage() || DGV->hasWeakLinkage())
     return GlobalValue::WeakLinkage;
-  else {
-    assert(SGV->hasInternalLinkage() && DGV->hasInternalLinkage() &&
-           "Unexpected linkage type");
+  else if (SGV->hasInternalLinkage() && DGV->hasInternalLinkage())
     return GlobalValue::InternalLinkage;
+  else {
+    assert (SGV->hasPrivateLinkage() && DGV->hasPrivateLinkage() &&
+           "Unexpected linkage type");
+    return GlobalValue::PrivateLinkage;
   }
 }
 
@@ -715,7 +717,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
     GlobalValue* DGV = NULL;
 
     // Try to find something 'similar' to SGA in destination module.
-    if (!DGV && !SGA->hasInternalLinkage()) {
+    if (!DGV && !SGA->hasLocalLinkage()) {
       DGV = Dest->getNamedAlias(SGA->getName());
 
       // If types don't agree due to opaque types, try to resolve them.
@@ -723,7 +725,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
         RecursiveResolveTypes(SGA->getType(), DGV->getType());
     }
 
-    if (!DGV && !SGA->hasInternalLinkage()) {
+    if (!DGV && !SGA->hasLocalLinkage()) {
       DGV = Dest->getGlobalVariable(SGA->getName());
 
       // If types don't agree due to opaque types, try to resolve them.
@@ -731,7 +733,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
         RecursiveResolveTypes(SGA->getType(), DGV->getType());
     }
 
-    if (!DGV && !SGA->hasInternalLinkage()) {
+    if (!DGV && !SGA->hasLocalLinkage()) {
       DGV = Dest->getFunction(SGA->getName());
 
       // If types don't agree due to opaque types, try to resolve them.
@@ -740,7 +742,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
     }
 
     // No linking to be performed on internal stuff.
-    if (DGV && DGV->hasInternalLinkage())
+    if (DGV && DGV->hasLocalLinkage())
       DGV = NULL;
 
     if (GlobalAlias *DGA = dyn_cast_or_null<GlobalAlias>(DGV)) {
@@ -831,7 +833,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
     // If the symbol table renamed the alias, but it is an externally visible
     // symbol, DGA must be an global value with internal linkage. Rename it.
     if (NewGA->getName() != SGA->getName() &&
-        !NewGA->hasInternalLinkage())
+        !NewGA->hasLocalLinkage())
       ForceRenaming(NewGA, SGA->getName());
 
     // Remember this mapping so uses in the source module get remapped
@@ -912,13 +914,13 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
     
     // Check to see if may have to link the function with the global, alias or
     // function.
-    if (SF->hasName() && !SF->hasInternalLinkage())
+    if (SF->hasName() && !SF->hasLocalLinkage())
       DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameStart(),
                                                         SF->getNameEnd()));
     
     // If we found a global with the same name in the dest module, but it has
     // internal linkage, we are really not doing any linkage here.
-    if (DGV && DGV->hasInternalLinkage())
+    if (DGV && DGV->hasLocalLinkage())
       DGV = 0;
 
     // If types don't agree due to opaque types, try to resolve them.
@@ -943,7 +945,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
       // If the LLVM runtime renamed the function, but it is an externally
       // visible symbol, DF must be an existing function with internal linkage.
       // Rename it.
-      if (!NewDF->hasInternalLinkage() && NewDF->getName() != SF->getName())
+      if (!NewDF->hasLocalLinkage() && NewDF->getName() != SF->getName())
         ForceRenaming(NewDF, SF->getName());
       
       // ... and remember this mapping...
@@ -982,7 +984,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
       // If the symbol table renamed the function, but it is an externally
       // visible symbol, DF must be an existing function with internal 
       // linkage.  Rename it.
-      if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage())
+      if (NewDF->getName() != SF->getName() && !NewDF->hasLocalLinkage())
         ForceRenaming(NewDF, SF->getName());
       
       // Remember this mapping so uses in the source module get remapped
index 7bef576057d1f32595347249104efd3673c5d0d7..eda6ff4266db1477a3f5461e7474c83dae2eef49 100644 (file)
@@ -808,7 +808,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
   GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
   Reloc::Model RelocM = getTargetMachine().getRelocationModel();
   if (RelocM == Reloc::PIC_) {
-    bool UseGOTOFF = GV->hasInternalLinkage() || GV->hasHiddenVisibility();
+    bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
     ARMConstantPoolValue *CPV =
       new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
     SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
index 40153dcb0a339dcee24e86ff604f3c50e54881ce..12e13466d1b393aca0c9d48d2430244623e23545 100644 (file)
@@ -197,6 +197,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   const Function *F = MF.getFunction();
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:
     SwitchToTextSection("\t.text", F);
     break;
@@ -847,11 +848,11 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
       }
     }
 
-    if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
+    if (GVar->hasLocalLinkage() || GVar->mayBeOverridden()) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (isDarwin) {
-        if (GVar->hasInternalLinkage()) {
+        if (GVar->hasLocalLinkage()) {
           O << TAI->getLCOMMDirective()  << name << "," << Size
             << ',' << Align;
         } else if (GVar->hasCommonLinkage()) {
@@ -869,7 +870,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
           return;
         }
       } else if (TAI->getLCOMMDirective() != NULL) {
-        if (GVar->hasInternalLinkage()) {
+        if (GVar->hasLocalLinkage()) {
           O << TAI->getLCOMMDirective() << name << "," << Size;
         } else {
           O << TAI->getCOMMDirective()  << name << "," << Size;
@@ -878,7 +879,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
         }
       } else {
         SwitchToSection(TAI->SectionForGlobal(GVar));
-        if (GVar->hasInternalLinkage())
+        if (GVar->hasLocalLinkage())
           O << "\t.local\t" << name << "\n";
         O << TAI->getCOMMDirective()  << name << "," << Size;
         if (TAI->getCOMMDirectiveTakesAlignment())
@@ -909,6 +910,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
    case GlobalValue::ExternalLinkage:
     O << "\t.globl " << name << "\n";
     // FALL THROUGH
+   case GlobalValue::PrivateLinkage:
    case GlobalValue::InternalLinkage:
     break;
    default:
index 793d475e0ddc68f7481f3bb43bb081197d10a05c..1c090ff3e2d347d7a051b275c765d36e34fb0bb5 100644 (file)
@@ -513,7 +513,7 @@ SDValue AlphaTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
     SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
 
     //    if (!GV->hasWeakLinkage() && !GV->isDeclaration() && !GV->hasLinkOnceLinkage()) {
-    if (GV->hasInternalLinkage()) {
+    if (GV->hasLocalLinkage()) {
       SDValue Hi = DAG.getNode(AlphaISD::GPRelHi,  MVT::i64, GA,
                                 DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i64));
       SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
index 35a43fbb9d1d5782f7c272c9fde8d46739205642..b2e63e606f43ae714f63e50991dbaa9e16737553 100644 (file)
@@ -169,6 +169,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   O << "\t.ent " << CurrentFnName << "\n";
 
+  assert (!F->hasPrivateLinkage() && "add private prefix.");
   O << CurrentFnName << ":\n";
 
   // Print out code for the function.
index 541a1feca550a250ea49d01e07c0d11ae379b9a6..53c986409687ca6745b57d0b51cce8a6708a6e62 100644 (file)
@@ -1910,7 +1910,7 @@ bool CWriter::doInitialization(Module &M) {
         if (getGlobalVariableClass(I))
           continue;
 
-        if (I->hasInternalLinkage())
+        if (I->hasLocalLinkage())
           Out << "static ";
         else
           Out << "extern ";
@@ -1946,7 +1946,7 @@ bool CWriter::doInitialization(Module &M) {
         if (getGlobalVariableClass(I))
           continue;
 
-        if (I->hasInternalLinkage())
+        if (I->hasLocalLinkage())
           Out << "static ";
         else if (I->hasDLLImportLinkage())
           Out << "__declspec(dllimport) ";
@@ -2190,7 +2190,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   /// isStructReturn - Should this function actually return a struct by-value?
   bool isStructReturn = F->hasStructRetAttr();
   
-  if (F->hasInternalLinkage()) Out << "static ";
+  if (F->hasLocalLinkage()) Out << "static ";
   if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
   if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";  
   switch (F->getCallingConv()) {
index d7b582b93a8c218d5244b5b0df463bb37465e076..326097c11407609c2cc9a8178fc4e4e4117980a5 100644 (file)
@@ -442,6 +442,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
 
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:  // Symbols default to internal.
     break;
   case Function::ExternalLinkage:
@@ -536,7 +537,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
-      (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
+      (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
        GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
@@ -545,7 +546,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
         O << "\t.type " << name << ", @object\n";
         O << name << ":\n";
         O << "\t.zero " << Size << '\n';
-      } else if (GVar->hasInternalLinkage()) {
+      } else if (GVar->hasLocalLinkage()) {
         O << TAI->getLCOMMDirective() << name << ',' << Size;
       } else {
         O << ".comm " << name << ',' << Size;
@@ -573,6 +574,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     O << "\t.global " << name << '\n'
       << "\t.type " << name << ", @object\n";
     // FALL THROUGH
+   case GlobalValue::PrivateLinkage:
    case GlobalValue::InternalLinkage:
     break;
    default:
@@ -617,4 +619,3 @@ FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
                                             SPUTargetMachine &tm) {
   return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
 }
-
index fff6ef034f12dd7c565951642286738d48bb83a3..dbe4f2d2d3010d946d08ba102ce5b2906328051a 100644 (file)
@@ -292,6 +292,8 @@ namespace {
     switch (LT) {
     case GlobalValue::InternalLinkage:
       Out << "GlobalValue::InternalLinkage"; break;
+    case GlobalValue::PrivateLinkage:
+      Out << "GlobalValue::PrivateLinkage"; break;
     case GlobalValue::LinkOnceLinkage:
       Out << "GlobalValue::LinkOnceLinkage "; break;
     case GlobalValue::WeakLinkage:
index ed32d39fcbd509379749ec48a6f0fadb4cebd91b..57e70148f481fbb8728a3752bfefa7db9d75d5fa 100644 (file)
@@ -61,7 +61,7 @@ DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
                                           Mangler *Mang) const {
   if (GV==0)
     return false;
-  if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
+  if (GV->hasLocalLinkage() && !isa<Function>(GV) &&
       ((strlen(getPrivateGlobalPrefix()) != 0 &&
         Mang->getValueName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
           getPrivateGlobalPrefix()) ||
index bf96d9bfa8e5d0740f656c03465505fb933fca7b..5a3b93a52f37b0ac78dfd9a92a9f31623bbed979 100644 (file)
@@ -44,6 +44,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
   if (const Function *F = dyn_cast<Function>(GV)) {
     switch (F->getLinkage()) {
      default: assert(0 && "Unknown linkage type!");
+     case Function::PrivateLinkage:
      case Function::InternalLinkage:
      case Function::DLLExportLinkage:
      case Function::ExternalLinkage:
@@ -184,4 +185,3 @@ std::string ELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
 
   return Flags;
 }
-
index 394821215b812b804bde1013d1f6ac4249ada905..cda0c06308ffe34403587941e9366817fd2af100 100644 (file)
@@ -275,10 +275,10 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
+        (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-      if (GVar->hasInternalLinkage()) {
+      if (GVar->hasLocalLinkage()) {
         O << "\t.lcomm " << name << "#," << Size
           << ',' << (1 << Align);
         O << '\n';
@@ -307,6 +307,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     O << TAI->getGlobalDirective() << name << '\n';
     // FALL THROUGH
    case GlobalValue::InternalLinkage:
+   case GlobalValue::PrivateLinkage:
     break;
    case GlobalValue::GhostLinkage:
     cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
index 8843d95f94606ad0191c7a3e1fcbdbcf27901b4d..e8b4d24c11ca192c4b5b25296db1ed6d18d818d3 100644 (file)
@@ -349,10 +349,10 @@ MSILWriter::ValueType MSILWriter::getValueLocation(const Value* V) {
     return ArgumentVT;
   // Function
   else if (const Function* F = dyn_cast<Function>(V))
-    return F->hasInternalLinkage() ? InternalVT : GlobalVT;
+    return F->hasLocalLinkage() ? InternalVT : GlobalVT;
   // Variable
   else if (const GlobalVariable* G = dyn_cast<GlobalVariable>(V))
-    return G->hasInternalLinkage() ? InternalVT : GlobalVT;
+    return G->hasLocalLinkage() ? InternalVT : GlobalVT;
   // Constant
   else if (isa<Constant>(V))
     return isa<ConstantExpr>(V) ? ConstExprVT : ConstVT;
@@ -1401,7 +1401,7 @@ void MSILWriter::printStaticInitializerList() {
 void MSILWriter::printFunction(const Function& F) {
   bool isSigned = F.paramHasAttr(0, Attribute::SExt);
   Out << "\n.method static ";
-  Out << (F.hasInternalLinkage() ? "private " : "public ");
+  Out << (F.hasLocalLinkage() ? "private " : "public ");
   if (F.isVarArg()) Out << "vararg ";
   Out << getTypeName(F.getReturnType(),isSigned) << 
     getConvModopt(F.getCallingConv()) << getValueName(&F) << '\n';
index 3971c752dd348820fe64fe4211476eb5c3e8d781..f6d8dda16a006a7b080cdbbd6e14fa667d7ad109 100644 (file)
@@ -275,9 +275,6 @@ runOnMachineFunction(MachineFunction &MF)
 
   O << "\n\n";
 
-  // What's my mangled name?
-  CurrentFnName = Mang->getValueName(MF.getFunction());
-
   // Emit the function start directives
   emitFunctionStart(MF);
 
@@ -384,7 +381,10 @@ printOperand(const MachineInstr *MI, int opNum)
       return;
 
     case MachineOperand::MO_GlobalAddress:
-      O << Mang->getValueName(MO.getGlobal());
+      {
+        const GlobalValue *GV = MO.getGlobal();
+        O << Mang->getValueName(GV);
+      }
       break;
 
     case MachineOperand::MO_ExternalSymbol:
@@ -449,7 +449,7 @@ printFCCOperand(const MachineInstr *MI, int opNum, const char *Modifier)
 bool MipsAsmPrinter::
 doInitialization(Module &M) 
 {
-  Mang = new Mangler(M);
+  Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
 
   // Tell the assembler which ABI we are using
   O << "\t.section .mdebug." << emitCurrentABIString() << '\n';
@@ -502,10 +502,10 @@ printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
+        (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-      if (GVar->hasInternalLinkage())
+      if (GVar->hasLocalLinkage())
         O << "\t.local\t" << name << '\n';
 
       O << TAI->getCOMMDirective() << name << ',' << Size;
@@ -531,6 +531,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
     // If external or appending, declare as a global symbol
     O << TAI->getGlobalDirective() << name << '\n';
     // Fall Through
+   case GlobalValue::PrivateLinkage:
    case GlobalValue::InternalLinkage:
     if (CVA && CVA->isCString())
       printSizeAndType = false;
index bca5ab2e18af813b641a95ab49c16b7748a5cd30..f2786dc12027d95d09d0870a2236fdc375d89514 100644 (file)
@@ -216,7 +216,7 @@ bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV)
 
   // if this is a internal constant string, there is a special
   // section for it, but not in small data/bss.
-  if (GVA->hasInitializer() && GV->hasInternalLinkage()) {
+  if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
     Constant *C = GVA->getInitializer();
     const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
     if (CVA && CVA->isCString()) 
@@ -489,7 +489,7 @@ LowerGlobalAddress(SDValue Op, SelectionDAG &DAG)
     SDValue ResNode = DAG.getLoad(MVT::i32, DAG.getEntryNode(), GA, NULL, 0);
     // On functions and global targets not internal linked only
     // a load from got/GP is necessary for PIC to work.
-    if (!GV->hasInternalLinkage() || isa<Function>(GV))
+    if (!GV->hasLocalLinkage() || isa<Function>(GV))
       return ResNode;
     SDValue Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA);
     return DAG.getNode(ISD::ADD, MVT::i32, ResNode, Lo);
index 605e6319d037927eefdde3a52ff62a5477f805fe..362e8d19da6ccab0afd545d7e2621ecbd5c8a296 100644 (file)
@@ -584,6 +584,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:  // Symbols default to internal.
     break;
   case Function::ExternalLinkage:
@@ -686,7 +687,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
-      (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
+      (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
        GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
@@ -695,7 +696,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
         O << "\t.type " << name << ", @object\n";
         O << name << ":\n";
         O << "\t.zero " << Size << '\n';
-      } else if (GVar->hasInternalLinkage()) {
+      } else if (GVar->hasLocalLinkage()) {
         O << TAI->getLCOMMDirective() << name << ',' << Size;
       } else {
         O << ".comm " << name << ',' << Size;
@@ -723,6 +724,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
       << "\t.type " << name << ", @object\n";
     // FALL THROUGH
    case GlobalValue::InternalLinkage:
+   case GlobalValue::PrivateLinkage:
     break;
    default:
     cerr << "Unknown linkage type!";
@@ -911,7 +913,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
-      (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
+      (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
        GVar->mayBeOverridden())) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
@@ -919,7 +921,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
       O << "\t.globl " << name << '\n';
       O << "\t.zerofill __DATA, __common, " << name << ", "
         << Size << ", " << Align;
-    } else if (GVar->hasInternalLinkage()) {
+    } else if (GVar->hasLocalLinkage()) {
       O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
     } else if (!GVar->hasCommonLinkage()) {
       O << "\t.globl " << name << '\n'
index af7c4d9cd1e401147abe175c850e106eef423a7a..a7f4ea2dda75c6cd8dcd53f3768f8bfbf5974aeb 100644 (file)
@@ -98,8 +98,6 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   static unsigned BBNumber = 0;
 
   O << "\n\n";
-  // What's my mangled name?
-  CurrentFnName = Mang->getValueName(MF.getFunction());
 
   // Print out the label for the function.
   const Function *F = MF.getFunction();
@@ -168,7 +166,10 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     printBasicBlockLabel(MO.getMBB());
     return;
   case MachineOperand::MO_GlobalAddress:
-    O << Mang->getValueName(MO.getGlobal());
+    {
+      const GlobalValue *GV = MO.getGlobal();
+      O << Mang->getValueName(GV);
+    }
     break;
   case MachineOperand::MO_ExternalSymbol:
     O << MO.getSymbolName();
@@ -218,7 +219,7 @@ void SparcAsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
 }
 
 bool SparcAsmPrinter::doInitialization(Module &M) {
-  Mang = new Mangler(M);
+  Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
   return false; // success
 }
 
@@ -255,10 +256,10 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
 
   if (C->isNullValue() && !GVar->hasSection()) {
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
+        (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-      if (GVar->hasInternalLinkage())
+      if (GVar->hasLocalLinkage())
         O << "\t.local " << name << '\n';
 
       O << TAI->getCOMMDirective() << name << ',' << Size;
@@ -284,6 +285,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     // If external or appending, declare as a global symbol
     O << TAI->getGlobalDirective() << name << '\n';
     // FALL THROUGH
+   case GlobalValue::PrivateLinkage:
    case GlobalValue::InternalLinkage:
     break;
    case GlobalValue::GhostLinkage:
index 5378967b658dd38f090637aed7355cf25285c2a4..df0b107f9d84b4446cc6ccf1f338098da9a1722c 100644 (file)
@@ -159,6 +159,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
   case Function::InternalLinkage:  // Symbols default to internal.
+  case Function::PrivateLinkage:
     EmitAlignment(FnAlign, F);
     break;
   case Function::DLLExportLinkage:
@@ -188,7 +189,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
   else if (Subtarget->isTargetCygMing()) {
     O << "\t.def\t " << CurrentFnName
       << ";\t.scl\t" <<
-      (F->getLinkage() == Function::InternalLinkage ? COFF::C_STAT : COFF::C_EXT)
+      (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
       << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
       << ";\t.endef\n";
   }
@@ -421,7 +422,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
         if (shouldPrintPLT(TM, Subtarget)) {
           // Assemble call via PLT for externally visible symbols
           if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
-              !GV->hasInternalLinkage())
+              !GV->hasLocalLinkage())
             O << "@PLT";
         }
         if (Subtarget->isTargetCygMing() && GV->isDeclaration())
@@ -789,11 +790,11 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     }
 
     if (!GVar->isThreadLocal() &&
-        (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
+        (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (TAI->getLCOMMDirective() != NULL) {
-        if (GVar->hasInternalLinkage()) {
+        if (GVar->hasLocalLinkage()) {
           O << TAI->getLCOMMDirective() << name << ',' << Size;
           if (Subtarget->isTargetDarwin())
             O << ',' << Align;
@@ -813,7 +814,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
         }
       } else {
         if (!Subtarget->isTargetCygMing()) {
-          if (GVar->hasInternalLinkage())
+          if (GVar->hasLocalLinkage())
             O << "\t.local\t" << name << '\n';
         }
         O << TAI->getCOMMDirective()  << name << ',' << Size;
@@ -849,6 +850,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     // If external or appending, declare as a global symbol
     O << "\t.globl " << name << '\n';
     // FALL THROUGH
+  case GlobalValue::PrivateLinkage:
   case GlobalValue::InternalLinkage:
      break;
   default:
index 58bd8debf8e1420a60f3e597373c6d08c6de05c7..a75422a56d5c928076ce35954a400120a27674d5 100644 (file)
@@ -145,6 +145,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     FnAlign = 1;
   switch (F->getLinkage()) {
   default: assert(0 && "Unsupported linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:
     EmitAlignment(FnAlign);
     break;
index 608f352ddf149fac746a69781c1b4ebf6fa95083..5dc5103727d5af752e9a59e2e5499a3418d63ea7 100644 (file)
@@ -56,7 +56,7 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
       // Extra load is needed for all externally visible.
       if (isDirectCall)
         return false;
-      if (GV->hasInternalLinkage() || GV->hasHiddenVisibility())
+      if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
         return false;
       return true;
     } else if (isTargetCygMing() || isTargetWindows()) {
@@ -79,7 +79,7 @@ bool X86Subtarget::GVRequiresRegister(const GlobalValue *GV,
   // returns false.
   if (TM.getRelocationModel() == Reloc::PIC_)
     return !isDirectCall && 
-      (GV->hasInternalLinkage() || GV->hasExternalLinkage());
+      (GV->hasLocalLinkage() || GV->hasExternalLinkage());
   return false;
 }
 
index 57530c39428f24d69ca8013ae992c9b5f1eaa183..53acd600520fb5430a891535febd37a91d663f13 100644 (file)
@@ -198,6 +198,7 @@ emitGlobal(const GlobalVariable *GV)
       }
       // FALL THROUGH
     case GlobalValue::InternalLinkage:
+    case GlobalValue::PrivateLinkage:
       break;
     case GlobalValue::GhostLinkage:
       cerr << "Should not have any unmaterialized functions!\n";
@@ -259,6 +260,7 @@ emitFunctionStart(MachineFunction &MF)
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
   case Function::InternalLinkage:  // Symbols default to internal.
+  case Function::PrivateLinkage:
     break;
   case Function::ExternalLinkage:
     emitGlobalDirective(CurrentFnName);
@@ -299,9 +301,6 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF)
   // Print out jump tables referenced by the function
   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
 
-  // What's my mangled name?
-  CurrentFnName = Mang->getValueName(MF.getFunction());
-
   // Emit the function start directives
   emitFunctionStart(MF);
   
@@ -367,9 +366,12 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     printBasicBlockLabel(MO.getMBB());
     break;
   case MachineOperand::MO_GlobalAddress:
-    O << Mang->getValueName(MO.getGlobal());
-    if (MO.getGlobal()->hasExternalWeakLinkage())
-      ExtWeakSymbols.insert(MO.getGlobal());
+    {
+      const GlobalValue *GV = MO.getGlobal();
+      O << Mang->getValueName(GV);
+      if (GV->hasExternalWeakLinkage())
+        ExtWeakSymbols.insert(GV);
+    }
     break;
   case MachineOperand::MO_ExternalSymbol:
     O << MO.getSymbolName();
index 00d06bab154fd3f4b5f4213d7b4035f409b23802..69e427e8ad1b4456a8c88d3bd279d0067de0207e 100644 (file)
@@ -114,7 +114,7 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
   Function *F = CGN->getFunction();
 
   // Make sure that it is local to this module.
-  if (!F || !F->hasInternalLinkage()) return false;
+  if (!F || !F->hasLocalLinkage()) return false;
 
   // First check: see if there are any pointer arguments!  If not, quick exit.
   SmallVector<std::pair<Argument*, unsigned>, 16> PointerArgs;
index b4bab2d0e7e8e8baa35ccdfe006ce62bff211853..237e6db1d335c50d292d89829fe5897e371c4430 100644 (file)
@@ -72,7 +72,7 @@ bool ConstantMerge::runOnModule(Module &M) {
       
       // If this GV is dead, remove it.
       GV->removeDeadConstantUsers();
-      if (GV->use_empty() && GV->hasInternalLinkage()) {
+      if (GV->use_empty() && GV->hasLocalLinkage()) {
         GV->eraseFromParent();
         continue;
       }
@@ -86,7 +86,7 @@ bool ConstantMerge::runOnModule(Module &M) {
 
         if (Slot == 0) {    // Nope, add it to the map.
           Slot = GV;
-        } else if (GV->hasInternalLinkage()) {    // Yup, this is a duplicate!
+        } else if (GV->hasLocalLinkage()) {    // Yup, this is a duplicate!
           // Make all uses of the duplicate constant use the canonical version.
           Replacements.push_back(std::make_pair(GV, Slot));
         }
index 8f0c4c41fced8f7c34e34763ada5bebb26968485..9d7980c0b2b9009e30ab9af747d074cfe51a1ae7 100644 (file)
@@ -172,7 +172,7 @@ ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); }
 /// llvm.vastart is never called, the varargs list is dead for the function.
 bool DAE::DeleteDeadVarargs(Function &Fn) {
   assert(Fn.getFunctionType()->isVarArg() && "Function isn't varargs!");
-  if (Fn.isDeclaration() || !Fn.hasInternalLinkage()) return false;
+  if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
 
   // Ensure that the function is only directly called.
   for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ++I) {
@@ -424,7 +424,7 @@ void DAE::SurveyFunction(Function &F) {
         return;
       }
 
-  if (!F.hasInternalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
+  if (!F.hasLocalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
     MarkLive(F);
     return;
   }
index 79e51d0332c4d2a58966ec88f3c9464676a2f806..0c529d239d98cf2e63a04ee066315cbebe8e39dd 100644 (file)
@@ -63,7 +63,7 @@ namespace {
                   I != E; ++I) {
                if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
                  Function* Callee = callInst->getCalledFunction();
-                 if (Callee && Callee->hasInternalLinkage())
+                 if (Callee && Callee->hasLocalLinkage())
                    Callee->setLinkage(GlobalValue::ExternalLinkage);
                }
              }
@@ -85,6 +85,7 @@ namespace {
 
     bool isolateGV(Module &M) {
       // Mark all globals internal
+      // FIXME: what should we do with private linkage?
       for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
         if (!I->isDeclaration()) {
           I->setLinkage(GlobalValue::InternalLinkage);
index a9c9ec0fd844abc66bd55150834c3f2a9caba936..a0f8923242f50107424c10b518f3c8de7b77cec5 100644 (file)
@@ -63,7 +63,7 @@ bool GlobalDCE::runOnModule(Module &M) {
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
     Changed |= RemoveUnusedGlobalValue(*I);
     // Functions with external linkage are needed if they have a body
-    if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
+    if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
         !I->isDeclaration())
       GlobalIsNeeded(I);
   }
@@ -73,7 +73,7 @@ bool GlobalDCE::runOnModule(Module &M) {
     Changed |= RemoveUnusedGlobalValue(*I);
     // Externally visible & appending globals are needed, if they have an
     // initializer.
-    if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
+    if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
         !I->isDeclaration())
       GlobalIsNeeded(I);
   }
index b4a5634d9e349ba06b223d23d9259643f89d9aca..99fc7317b1fab1b54649a692d96dab0008cb4979 100644 (file)
@@ -464,7 +464,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) {
   if (!GlobalUsersSafeToSRA(GV))
     return 0;
   
-  assert(GV->hasInternalLinkage() && !GV->isConstant());
+  assert(GV->hasLocalLinkage() && !GV->isConstant());
   Constant *Init = GV->getInitializer();
   const Type *Ty = Init->getType();
 
@@ -1808,12 +1808,12 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
   for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
     Function *F = FI++;
     F->removeDeadConstantUsers();
-    if (F->use_empty() && (F->hasInternalLinkage() ||
+    if (F->use_empty() && (F->hasLocalLinkage() ||
                            F->hasLinkOnceLinkage())) {
       M.getFunctionList().erase(F);
       Changed = true;
       ++NumFnDeleted;
-    } else if (F->hasInternalLinkage()) {
+    } else if (F->hasLocalLinkage()) {
       if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
           OnlyCalledDirectly(F)) {
         // If this function has C calling conventions, is not a varargs
@@ -1843,7 +1843,7 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
   for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
        GVI != E; ) {
     GlobalVariable *GV = GVI++;
-    if (!GV->isConstant() && GV->hasInternalLinkage() &&
+    if (!GV->isConstant() && GV->hasLocalLinkage() &&
         GV->hasInitializer())
       Changed |= ProcessInternalGlobal(GV, GVI);
   }
@@ -1982,7 +1982,7 @@ static Constant *getVal(DenseMap<Value*, Constant*> &ComputedValues,
 /// globals.  This should be kept up to date with CommitValueTo.
 static bool isSimpleEnoughPointerToCommit(Constant *C) {
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
-    if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
+    if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
       return false;  // do not allow weak/linkonce/dllimport/dllexport linkage.
     return !GV->isDeclaration();  // reject external globals.
   }
@@ -1991,7 +1991,7 @@ static bool isSimpleEnoughPointerToCommit(Constant *C) {
     if (CE->getOpcode() == Instruction::GetElementPtr &&
         isa<GlobalVariable>(CE->getOperand(0))) {
       GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
-      if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
+      if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
         return false;  // do not allow weak/linkonce/dllimport/dllexport linkage.
       return GV->hasInitializer() &&
              ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE);
index 5bd7a3d4cc008321b4a4b9d562c2585e1cdf93e2..6ae8276d5247616f97f820b2ee09a2bf35706d32 100644 (file)
@@ -63,7 +63,7 @@ bool IPCP::runOnModule(Module &M) {
       if (!I->isDeclaration()) {
         // Delete any klingons.
         I->removeDeadConstantUsers();
-        if (I->hasInternalLinkage())
+        if (I->hasLocalLinkage())
           LocalChange |= PropagateConstantsIntoArguments(*I);
         Changed |= PropagateConstantReturn(*I);
       }
index 8d40c9beef4d9d5cc9bd758647a06b4ed27456e5..ed177478e167448161904cc5b798ceb2905a3067 100644 (file)
@@ -68,7 +68,7 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
 
   // If we inlined the last possible call site to the function, delete the
   // function body now.
-  if (Callee->use_empty() && Callee->hasInternalLinkage() &&
+  if (Callee->use_empty() && Callee->hasLocalLinkage() &&
       !SCCFunctions.count(Callee)) {
     DOUT << "    -> Deleting dead function: " << Callee->getName() << "\n";
     CallGraphNode *CalleeNode = CG[Callee];
@@ -240,7 +240,7 @@ bool Inliner::removeDeadFunctions(CallGraph &CG,
       if (DNR && DNR->count(F))
         continue;
 
-      if ((F->hasLinkOnceLinkage() || F->hasInternalLinkage()) &&
+      if ((F->hasLinkOnceLinkage() || F->hasLocalLinkage()) &&
           F->use_empty()) {
 
         // Remove any call graph edges from the function to its callees.
index b6d89aafd0f0a37b433fcaddf874200c212c06ea..b226d1959a0115e9bcb2a9a733afe8b37584d2ed 100644 (file)
@@ -121,9 +121,10 @@ bool InternalizePass::runOnModule(Module &M) {
   bool Changed = false;
 
   // Mark all functions not in the api as internal.
+  // FIXME: maybe use private linkage?
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isDeclaration() &&         // Function must be defined here
-        !I->hasInternalLinkage() &&  // Can't already have internal linkage
+        !I->hasLocalLinkage() &&  // Can't already have internal linkage
         !ExternalNames.count(I->getName())) {// Not marked to keep external?
       I->setLinkage(GlobalValue::InternalLinkage);
       // Remove a callgraph edge from the external node to this function.
@@ -149,9 +150,10 @@ bool InternalizePass::runOnModule(Module &M) {
 
   // Mark all global variables with initializers that are not in the api as
   // internal as well.
+  // FIXME: maybe use private linkage?
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I)
-    if (!I->isDeclaration() && !I->hasInternalLinkage() &&
+    if (!I->isDeclaration() && !I->hasLocalLinkage() &&
         !ExternalNames.count(I->getName())) {
       I->setLinkage(GlobalValue::InternalLinkage);
       Changed = true;
index 3c5c258f710b94d19d73406ebfe0800e03a75583..17bc2d41a4cffcfb2b32bf28f639ca03146aabe4 100644 (file)
@@ -245,7 +245,7 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
   Function *G = FnVec[j];
 
   if (!F->mayBeOverridden()) {
-    if (G->hasInternalLinkage()) {
+    if (G->hasLocalLinkage()) {
       F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
       G->replaceAllUsesWith(F);
       G->eraseFromParent();
@@ -329,7 +329,7 @@ bool MergeFunctions::runOnModule(Module &M) {
     if (F->isDeclaration() || F->isIntrinsic())
       continue;
 
-    if (!F->hasInternalLinkage() && !F->hasExternalLinkage() &&
+    if (!F->hasLocalLinkage() && !F->hasExternalLinkage() &&
         !F->hasWeakLinkage())
       continue;
 
index 7e225e2bd555f33e74d53ac786af5d33ae715dc7..47a18e25283b706028204bff54fa4a38cfafe6d9 100644 (file)
@@ -95,7 +95,7 @@ static void RemoveDeadConstant(Constant *C) {
         OnlyUsedBy(C->getOperand(i), C)) 
       Operands.insert(C->getOperand(i));
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
-    if (!GV->hasInternalLinkage()) return;   // Don't delete non static globals.
+    if (!GV->hasLocalLinkage()) return;   // Don't delete non static globals.
     GV->eraseFromParent();
   }
   else if (!isa<Function>(C))
@@ -114,7 +114,7 @@ static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
   for (ValueSymbolTable::iterator VI = ST.begin(), VE = ST.end(); VI != VE; ) {
     Value *V = VI->getValue();
     ++VI;
-    if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasInternalLinkage()) {
+    if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
       if (!PreserveDbgInfo || strncmp(V->getNameStart(), "llvm.dbg", 8))
         // Set name to "", removing from symbol table!
         V->setName("");
@@ -162,13 +162,13 @@ bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
 
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I) {
-    if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
+    if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
       if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
         I->setName("");     // Internal symbols can't participate in linkage
   }
   
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
-    if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
+    if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
       if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
         I->setName("");     // Internal symbols can't participate in linkage
     StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
@@ -268,6 +268,7 @@ bool StripDebugInfo(Module &M) {
 
   // llvm.dbg.compile_units and llvm.dbg.subprograms are marked as linkonce
   // but since we are removing all debug information, make them internal now.
+  // FIXME: Use private linkage maybe?
   if (Constant *C = M.getNamedGlobal("llvm.dbg.compile_units"))
     if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
       GV->setLinkage(GlobalValue::InternalLinkage);
@@ -299,7 +300,7 @@ bool StripDebugInfo(Module &M) {
     Constant *C = DeadConstants.back();
     DeadConstants.pop_back();
     if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
-      if (GV->hasInternalLinkage())
+      if (GV->hasLocalLinkage())
         RemoveDeadConstant(GV);
     }
     else
@@ -329,4 +330,3 @@ bool StripSymbols::runOnModule(Module &M) {
 bool StripNonDebugSymbols::runOnModule(Module &M) {
   return StripSymbolNames(M, true);
 }
-
index 96ef66c1272fd75cd6a61c268a479feb19c6b53c..00556f963352ad602f80750267e84b63b7b2eb76 100644 (file)
@@ -82,7 +82,7 @@ bool SRETPromotion::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
 bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
   Function *F = CGN->getFunction();
 
-  if (!F || F->isDeclaration() || !F->hasInternalLinkage())
+  if (!F || F->isDeclaration() || !F->hasLocalLinkage())
     return false;
 
   // Make sure that function returns struct.
index dfb47954591e33616ad02e11a4de1506cc739df5..7adc80fb5a577187bfc390e0512fcb82988cffc1 100644 (file)
@@ -203,7 +203,7 @@ public:
   /// and out of the specified function (which cannot have its address taken),
   /// this method must be called.
   void AddTrackedFunction(Function *F) {
-    assert(F->hasInternalLinkage() && "Can only track internal functions!");
+    assert(F->hasLocalLinkage() && "Can only track internal functions!");
     // Add an entry, F -> undef.
     if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
       for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
@@ -609,7 +609,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
 
   Function *F = I.getParent()->getParent();
   // If we are tracking the return value of this function, merge it in.
-  if (!F->hasInternalLinkage())
+  if (!F->hasLocalLinkage())
     return;
 
   if (!TrackedRetVals.empty() && I.getNumOperands() == 1) {
@@ -1170,7 +1170,7 @@ void SCCPSolver::visitCallSite(CallSite CS) {
   // The common case is that we aren't tracking the callee, either because we
   // are not doing interprocedural analysis or the callee is indirect, or is
   // external.  Handle these cases first.
-  if (F == 0 || !F->hasInternalLinkage()) {
+  if (F == 0 || !F->hasLocalLinkage()) {
 CallOverdefined:
     // Void return and not tracking callee, just bail.
     if (I->getType() == Type::VoidTy) return;
@@ -1656,7 +1656,7 @@ bool IPSCCP::runOnModule(Module &M) {
   // taken or that are external as overdefined.
   //
   for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
-    if (!F->hasInternalLinkage() || AddressIsTaken(F)) {
+    if (!F->hasLocalLinkage() || AddressIsTaken(F)) {
       if (!F->isDeclaration())
         Solver.MarkBlockExecutable(F->begin());
       for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end();
@@ -1671,7 +1671,7 @@ bool IPSCCP::runOnModule(Module &M) {
   // their addresses taken, we can propagate constants through them.
   for (Module::global_iterator G = M.global_begin(), E = M.global_end();
        G != E; ++G)
-    if (!G->isConstant() && G->hasInternalLinkage() && !AddressIsTaken(G))
+    if (!G->isConstant() && G->hasLocalLinkage() && !AddressIsTaken(G))
       Solver.TrackValueOfGlobalVariable(G);
 
   // Solve for constants.
index 8c8a85eda9de274a7c6159b8082772084a108900..8e51dc09e24958d5d79e56ad566071a1a98cbc01 100644 (file)
@@ -130,7 +130,7 @@ void BasicInlinerImpl::inlineFunctions() {
         
         // Inline
         if (InlineFunction(CS, NULL, TD)) {
-          if (Callee->use_empty() && Callee->hasInternalLinkage())
+          if (Callee->use_empty() && Callee->hasLocalLinkage())
             DeadFunctions.insert(Callee);
           Changed = true;
           CallSites.erase(CallSites.begin() + index);
index 97f0bf802545d9d0030aa6d6b04a0be039e81ace..80516723d0ca6f3feaf122156a01fc3e947b6fee 100644 (file)
@@ -199,7 +199,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
   // If there is only one call of the function, and it has internal linkage,
   // make it almost guaranteed to be inlined.
   //
-  if (Callee->hasInternalLinkage() && Callee->hasOneUse())
+  if (Callee->hasLocalLinkage() && Callee->hasOneUse())
     InlineCost -= 15000;
   
   // If this function uses the coldcc calling convention, prefer not to inline
index bdc50b6c6971c4c5e45b83b725873884b33d82fa..b59ec0863b352e480906b6d4653ad8fc9896eb09 100644 (file)
@@ -1149,6 +1149,7 @@ void AssemblyWriter::printModule(const Module *M) {
 
 static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) {
   switch (LT) {
+  case GlobalValue::PrivateLinkage:      Out << "private "; break;
   case GlobalValue::InternalLinkage:     Out << "internal "; break;
   case GlobalValue::LinkOnceLinkage:     Out << "linkonce "; break;
   case GlobalValue::WeakLinkage:         Out << "weak "; break;
index 148849452c264bc313763a2c7de9efa2d6060cb3..36cfbf766a796a15f1e87824b7adb393539b282d 100644 (file)
@@ -147,14 +147,20 @@ std::string Mangler::getValueName(const GlobalValue *GV, const char * Suffix) {
     Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(GlobalID++);
   } else {
     Name = makeNameProper(GV->getName() + Suffix, Prefix);
+    std::string prefix;
+    if (GV->hasPrivateLinkage())
+      prefix = PrivatePrefix;
+    else
+      prefix = "";
+    Name = prefix + Name;
   }
 
   return Name;
 }
 
-Mangler::Mangler(Module &M, const char *prefix)
-  : Prefix(prefix), UseQuotes(false), PreserveAsmNames(false),
-    Count(0), TypeCounter(0) {
+Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
+  : Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false),
+    PreserveAsmNames(false), Count(0), TypeCounter(0) {
   std::fill(AcceptableChars, array_endof(AcceptableChars), 0);
 
   // Letters and numbers are acceptable.
index d5b48c0a73b3d29a83d89b97ef6d923b7823f5de..ef94796b24285df3b317bbf876300709ecae0a48 100644 (file)
@@ -153,7 +153,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
   }
 
   // Okay, the function exists.  Does it have externally visible linkage?
-  if (F->hasInternalLinkage()) {
+  if (F->hasLocalLinkage()) {
     // Clear the function's name.
     F->setName("");
     // Retry, now there won't be a conflict.
@@ -238,14 +238,14 @@ Function *Module::getFunction(const char *Name) const {
 /// symbol table.  If it does not exist, return null.  The type argument
 /// should be the underlying type of the global, i.e., it should not have
 /// the top-level PointerType, which represents the address of the global.
-/// If AllowInternal is set to true, this function will return types that
-/// have InternalLinkage. By default, these types are not returned.
+/// If AllowLocal is set to true, this function will return types that
+/// have an local. By default, these types are not returned.
 ///
 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
-                                          bool AllowInternal) const {
+                                          bool AllowLocal) const {
   if (Value *V = ValSymTab->lookup(Name)) {
     GlobalVariable *Result = dyn_cast<GlobalVariable>(V);
-    if (Result && (AllowInternal || !Result->hasInternalLinkage()))
+    if (Result && (AllowLocal || !Result->hasLocalLinkage()))
       return Result;
   }
   return 0;
@@ -376,4 +376,3 @@ void Module::removeLibrary(const std::string& Lib) {
       return;
     }
 }
-
index 47441032af9673920893a42a65da6736438a9d41..790a994f793b203729db3f91fb312bd5679e6771 100644 (file)
@@ -350,7 +350,7 @@ void Verifier::visitGlobalValue(GlobalValue &GV) {
           GV.hasExternalWeakLinkage() ||
           GV.hasGhostLinkage() ||
           (isa<GlobalAlias>(GV) &&
-           (GV.hasInternalLinkage() || GV.hasWeakLinkage())),
+           (GV.hasLocalLinkage() || GV.hasWeakLinkage())),
   "Global is external, but doesn't have external or dllimport or weak linkage!",
           &GV);
 
@@ -384,7 +384,7 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
 void Verifier::visitGlobalAlias(GlobalAlias &GA) {
   Assert1(!GA.getName().empty(),
           "Alias name cannot be empty!", &GA);
-  Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() ||
+  Assert1(GA.hasExternalLinkage() || GA.hasLocalLinkage() ||
           GA.hasWeakLinkage(),
           "Alias should have external or external weak linkage!", &GA);
   Assert1(GA.getAliasee(),
diff --git a/test/Assembler/private.ll b/test/Assembler/private.ll
new file mode 100644 (file)
index 0000000..3714572
--- /dev/null
@@ -0,0 +1,9 @@
+; Test to make sure that the 'private' tag is not lost!
+;
+; RUN: llvm-as < %s | llvm-dis | grep private
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
diff --git a/test/CodeGen/ARM/private.ll b/test/CodeGen/ARM/private.ll
new file mode 100644 (file)
index 0000000..e5eeccb
--- /dev/null
@@ -0,0 +1,22 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -mtriple=arm-linux-gnueabi > %t
+; RUN: grep .Lfoo: %t
+; RUN: egrep bl.*\.Lfoo %t
+; RUN: grep .Lbaz: %t
+; RUN: grep long.*\.Lbaz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
+
diff --git a/test/CodeGen/Alpha/private.ll b/test/CodeGen/Alpha/private.ll
new file mode 100644 (file)
index 0000000..8bb8253
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc > %t
+; RUN: grep .Lfoo: %t
+; RUN: grep call.*\.Lfoo %t
+; RUN: grep .Lbaz: %t
+; RUN: grep movl.*\.Lbaz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/CellSPU/private.ll b/test/CodeGen/CellSPU/private.ll
new file mode 100644 (file)
index 0000000..91567ce
--- /dev/null
@@ -0,0 +1,22 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -march=cellspu > %t
+; RUN: grep .Lfoo: %t
+; RUN: grep brsl.*\.Lfoo %t
+; RUN: grep .Lbaz: %t
+; RUN: grep ila.*\.Lbaz %t
+
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/IA64/private.ll b/test/CodeGen/IA64/private.ll
new file mode 100644 (file)
index 0000000..04170a9
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -march=ia64 > %t
+; RUN: grep .foo: %t
+; RUN: grep br.call.sptk.*\.foo %t
+; RUN: grep .baz: %t
+; RUN: grep ltoff.*\.baz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/Mips/private.ll b/test/CodeGen/Mips/private.ll
new file mode 100644 (file)
index 0000000..00a969d
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -march=mips > %t
+; RUN: grep \\\$foo: %t
+; RUN: grep call.*\\\$foo %t
+; RUN: grep \\\$baz: %t
+; RUN: grep lw.*\\\$baz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/PowerPC/private.ll b/test/CodeGen/PowerPC/private.ll
new file mode 100644 (file)
index 0000000..e25d293
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu > %t
+; RUN: grep .Lfoo: %t
+; RUN: grep bl.*\.Lfoo %t
+; RUN: grep .Lbaz: %t
+; RUN: grep lis.*\.Lbaz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/SPARC/private.ll b/test/CodeGen/SPARC/private.ll
new file mode 100644 (file)
index 0000000..a9850b7
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc  -march=sparc > %t
+; RUN: grep .foo: %t
+; RUN: grep call.*\.foo %t
+; RUN: grep .baz: %t
+; RUN: grep ld.*\.baz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/X86/private.ll b/test/CodeGen/X86/private.ll
new file mode 100644 (file)
index 0000000..caf1035
--- /dev/null
@@ -0,0 +1,20 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lfoo:
+; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep call.*\.Lfoo
+; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lbaz:
+; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep movl.*\.Lbaz
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
diff --git a/test/CodeGen/XCore/private.ll b/test/CodeGen/XCore/private.ll
new file mode 100644 (file)
index 0000000..888ccdf
--- /dev/null
@@ -0,0 +1,21 @@
+; Test to make sure that the 'private' is used correctly.
+;
+; RUN: llvm-as < %s | llc -march=xcore > %t
+; RUN: grep .Lfoo: %t
+; RUN: grep bl.*\.Lfoo %t
+; RUN: grep .Lbaz: %t
+; RUN: grep ldw.*\.Lbaz %t
+
+declare void @foo()
+
+define private void @foo() {
+        ret void
+}
+
+@baz = private global i32 4;
+
+define i32 @bar() {
+        call void @foo()
+       %1 = load i32* @baz, align 4
+        ret i32 %1
+}
index 776922aa5d43c32efb168e86a52aecd5bd0a6ca9..811169d86f88acab2d960366ed8b65d43beb3e1b 100644 (file)
@@ -199,7 +199,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
 /// prune appropriate entries out of M1s list.
 static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
   GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
-  if (!GV || GV->isDeclaration() || GV->hasInternalLinkage() ||
+  if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
       !GV->use_empty()) return;
   
   std::vector<std::pair<Function*, int> > M1Tors, M2Tors;
index 008c2e0431fca956121cc8abd9584a420a592f3f..ca4654d7931c21ba10ded69ea61e5b0f52b288ff 100644 (file)
@@ -68,6 +68,7 @@ namespace {
 }
 
 static char TypeCharForSymbol(GlobalValue &GV) {
+  /* FIXME: what to do with private linkage? */
   if (GV.isDeclaration())                                  return 'U';
   if (GV.hasLinkOnceLinkage())                             return 'C';
   if (GV.hasCommonLinkage())                               return 'C';
@@ -91,7 +92,7 @@ static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
     return;
   if ((TypeChar == 'U') && DefinedOnly)
     return;
-  if (GV.hasInternalLinkage () && ExternalOnly)
+  if (GV.hasLocalLinkage () && ExternalOnly)
     return;
   if (OutputFormat == posix) {
     std::cout << GV.getName () << " " << TypeCharForSymbol (GV) << " "