diff options
72 files changed, 401 insertions, 145 deletions
diff --git a/docs/LangRef.html b/docs/LangRef.html index e097c2a..5eef225 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -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> diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index b0e58d4..8fb5580 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -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; } diff --git a/include/llvm/Module.h b/include/llvm/Module.h index af687c8..b0db50a 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -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. diff --git a/include/llvm/Support/Mangler.h b/include/llvm/Support/Mangler.h index 771c09e..7820b85 100644 --- a/include/llvm/Support/Mangler.h +++ b/include/llvm/Support/Mangler.h @@ -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. diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 38b29fe..8584d06 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -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()) { diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index 1dfca60..c1082a0 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -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? diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp index 99e9d21..a795ca6 100644 --- a/lib/Analysis/IPA/GlobalsModRef.cpp +++ b/lib/Analysis/IPA/GlobalsModRef.cpp @@ -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)) diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp index 776f4dd..c6c89d2 100644 --- a/lib/Archive/Archive.cpp +++ b/lib/Archive/Archive.cpp @@ -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()); diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 6a3777d..fb491d3 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -453,6 +453,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(declare); KEYWORD(define); KEYWORD(global); KEYWORD(constant); + KEYWORD(private); KEYWORD(internal); KEYWORD(linkonce); KEYWORD(weak); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index edfdf15..401dc39 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -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: diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index 75a483f..e3bc908 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -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, diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 2d994d4..8770028 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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; } } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 81a1a37..da400a7 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -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; } } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 6627543..5b665a0 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -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()); diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 09d169b..02f27d1 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -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"; } diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 5d2fca1..b698178 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -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; diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index ae1f0d4..ef37db8 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -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; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 60a4f61..49b7ad8 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -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")) || diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 9c75928..a1fbdd2 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -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. diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 1db3662..dc502c1 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -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(); } diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp index 6cab77c..551cc8c 100644 --- a/lib/Linker/LinkArchives.cpp +++ b/lib/Linker/LinkArchives.cpp @@ -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()); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index b8b36ad..001db21 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -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 <, 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 diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index 7bef576..eda6ff4 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -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); diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 40153dc..12e1346 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -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: diff --git a/lib/Target/Alpha/AlphaISelLowering.cpp b/lib/Target/Alpha/AlphaISelLowering.cpp index 793d475..1c090ff 100644 --- a/lib/Target/Alpha/AlphaISelLowering.cpp +++ b/lib/Target/Alpha/AlphaISelLowering.cpp @@ -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); diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index 35a43fb..b2e63e6 100644 --- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -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. diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 541a1fe..53c9864 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -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()) { diff --git a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index d7b582b..326097c 100644 --- a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -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()); } - diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index fff6ef0..dbe4f2d 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -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: diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index ed32d39..57e7014 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -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()) || diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index bf96d9b..5a3b93a 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -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; } - diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp index 3948212..cda0c06 100644 --- a/lib/Target/IA64/IA64AsmPrinter.cpp +++ b/lib/Target/IA64/IA64AsmPrinter.cpp @@ -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"; diff --git a/lib/Target/MSIL/MSILWriter.cpp b/lib/Target/MSIL/MSILWriter.cpp index 8843d95..e8b4d24 100644 --- a/lib/Target/MSIL/MSILWriter.cpp +++ b/lib/Target/MSIL/MSILWriter.cpp @@ -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'; diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp index 3971c75..f6d8dda 100644 --- a/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/MipsAsmPrinter.cpp @@ -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; diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp index bca5ab2..f2786dc 100644 --- a/lib/Target/Mips/MipsISelLowering.cpp +++ b/lib/Target/Mips/MipsISelLowering.cpp @@ -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); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 605e631..362e8d1 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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' diff --git a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp index af7c4d9..a7f4ea2 100644 --- a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp @@ -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: diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 5378967..df0b107 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -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: diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp index 58bd8de..a75422a 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -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; diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index 608f352..5dc5103 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -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; } diff --git a/lib/Target/XCore/XCoreAsmPrinter.cpp b/lib/Target/XCore/XCoreAsmPrinter.cpp index 57530c3..53acd60 100644 --- a/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -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(); diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 00d06ba..69e427e 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -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; diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp index b4bab2d..237e6db 100644 --- a/lib/Transforms/IPO/ConstantMerge.cpp +++ b/lib/Transforms/IPO/ConstantMerge.cpp @@ -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)); } diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 8f0c4c4..9d7980c 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -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; } diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index 79e51d0..0c529d2 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -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); diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index a9c9ec0..a0f8923 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -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); } diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index b4a5634..99fc731 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -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); diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index 5bd7a3d..6ae8276 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -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); } diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 8d40c9b..ed17747 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -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. diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index b6d89aa..b226d19 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -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; diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index 3c5c258..17bc2d4 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -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; diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index 7e225e2..47a18e2 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -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); } - diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index 96ef66c..00556f9 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -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. diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index dfb4795..7adc80f 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -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. diff --git a/lib/Transforms/Utils/BasicInliner.cpp b/lib/Transforms/Utils/BasicInliner.cpp index 8c8a85e..8e51dc0 100644 --- a/lib/Transforms/Utils/BasicInliner.cpp +++ b/lib/Transforms/Utils/BasicInliner.cpp @@ -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); diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index 97f0bf8..8051672 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -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 diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index bdc50b6..b59ec08 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -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; diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp index 1488494..36cfbf7 100644 --- a/lib/VMCore/Mangler.cpp +++ b/lib/VMCore/Mangler.cpp @@ -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. diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index d5b48c0..ef94796 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -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; } } - diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 4744103..790a994 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -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 index 0000000..3714572 --- /dev/null +++ b/test/Assembler/private.ll @@ -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 index 0000000..e5eeccb --- /dev/null +++ b/test/CodeGen/ARM/private.ll @@ -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 index 0000000..8bb8253 --- /dev/null +++ b/test/CodeGen/Alpha/private.ll @@ -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 index 0000000..91567ce --- /dev/null +++ b/test/CodeGen/CellSPU/private.ll @@ -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 index 0000000..04170a9 --- /dev/null +++ b/test/CodeGen/IA64/private.ll @@ -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 index 0000000..00a969d --- /dev/null +++ b/test/CodeGen/Mips/private.ll @@ -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 index 0000000..e25d293 --- /dev/null +++ b/test/CodeGen/PowerPC/private.ll @@ -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 index 0000000..a9850b7 --- /dev/null +++ b/test/CodeGen/SPARC/private.ll @@ -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 index 0000000..caf1035 --- /dev/null +++ b/test/CodeGen/X86/private.ll @@ -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 index 0000000..888ccdf --- /dev/null +++ b/test/CodeGen/XCore/private.ll @@ -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 +} diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 776922a..811169d 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -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; diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 008c2e0..ca4654d 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -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) << " " |