llvm.org GIT mirror llvm / bb46f52
Add the private linkage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62279 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 11 years ago
72 changed file(s) with 401 addition(s) and 145 deletion(s). Raw diff Collapse all Expand all
479479
480480
481481
482
private:
483
484
Global values with private linkage are only directly accessible by
485 objects in the current module. In particular, linking code into a module with
486 an private global value may cause the private to be renamed as necessary to
487 avoid collisions. Because the symbol is private to the module, all
488 references can be updated. This doesn't show up in any symbol table in the
489 object file.
490
491
482492
internal:
483493
484
Global values with internal linkage are only directly accessible by
485 objects in the current module. In particular, linking code into a module with
486 an internal global value may cause the internal to be renamed as necessary to
487 avoid collisions. Because the symbol is internal to the module, all
488 references can be updated. This corresponds to the notion of the
494
Similar to private, but the value show as a local symbol (STB_LOCAL in
495 the case of ELF) in the object file. This corresponds to the notion of the
489496 'static' keyword in C.
490497
491498
3434 WeakLinkage, ///< Keep one copy of named function when linking (weak)
3535 AppendingLinkage, ///< Special purpose, only applies to global arrays
3636 InternalLinkage, ///< Rename collisions when linking (static functions)
37 PrivateLinkage, ///< Like Internal, but omit from symbol table
3738 DLLImportLinkage, ///< Function to be imported from DLL
3839 DLLExportLinkage, ///< Function to be accessible from DLL
3940 ExternalWeakLinkage,///< ExternalWeak linkage description
103104 bool hasCommonLinkage() const { return Linkage == CommonLinkage; }
104105 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
105106 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
107 bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; }
108 bool hasLocalLinkage() const {
109 return Linkage == InternalLinkage || Linkage == PrivateLinkage;
110 }
106111 bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; }
107112 bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; }
108113 bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; }
187187 /// getOrInsertFunction - Look up the specified function in the module symbol
188188 /// table. Four possibilities:
189189 /// 1. If it does not exist, add a prototype for the function and return it.
190 /// 2. If it exists, and has internal linkage, the existing function is
190 /// 2. If it exists, and has a local linkage, the existing function is
191191 /// renamed and a new one is inserted.
192192 /// 3. Otherwise, if the existing function has the correct prototype, return
193193 /// the existing function.
2828 /// symbol is marked as not needing this prefix.
2929 const char *Prefix;
3030
31 const char *PrivatePrefix;
3132 /// UseQuotes - If this is set, the target accepts global names in quotes,
3233 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
3334 /// the space character. By default, this is false.
5758
5859 // Mangler ctor - if a prefix is specified, it will be prepended onto all
5960 // symbols.
60 Mangler(Module &M, const char *Prefix = "");
61 Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "");
6162
6263 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
6364 /// strings for assembler labels.
10831083 // At some point we should just add constraints for the escaping functions
10841084 // at solve time, but this slows down solving. For now, we simply mark
10851085 // address taken functions as escaping and treat them as external.
1086 if (!F->hasInternalLinkage() || AnalyzeUsesOfFunction(F))
1086 if (!F->hasLocalLinkage() || AnalyzeUsesOfFunction(F))
10871087 AddConstraintsForNonInternalLinkage(F);
10881088
10891089 if (!F->isDeclaration()) {
111111 CallGraphNode *Node = getOrInsertFunction(F);
112112
113113 // If this function has external linkage, anything could call it.
114 if (!F->hasInternalLinkage()) {
114 if (!F->hasLocalLinkage()) {
115115 ExternalCallingNode->addCalledFunction(CallSite(), Node);
116116
117117 // Found the entry point?
163163 void GlobalsModRef::AnalyzeGlobals(Module &M) {
164164 std::vector Readers, Writers;
165165 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
166 if (I->hasInternalLinkage()) {
166 if (I->hasLocalLinkage()) {
167167 if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
168168 // Remember that we are tracking this global.
169169 NonAddressTakenGlobals.insert(I);
174174
175175 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
176176 I != E; ++I)
177 if (I->hasInternalLinkage()) {
177 if (I->hasLocalLinkage()) {
178178 if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
179179 // Remember that we are tracking this global, and the mod/ref fns
180180 NonAddressTakenGlobals.insert(I);
503503 // If we are asking for mod/ref info of a direct call with a pointer to a
504504 // global we are tracking, return information if we have it.
505505 if (GlobalValue *GV = dyn_cast(P->getUnderlyingObject()))
506 if (GV->hasInternalLinkage())
506 if (GV->hasLocalLinkage())
507507 if (Function *F = CS.getCalledFunction())
508508 if (NonAddressTakenGlobals.count(GV))
509509 if (FunctionRecord *FR = getFunctionInfo(F))
187187 static void getSymbols(Module*M, std::vector& symbols) {
188188 // Loop over global variables
189189 for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
190 if (!GI->isDeclaration() && !GI->hasInternalLinkage())
190 if (!GI->isDeclaration() && !GI->hasLocalLinkage())
191191 if (!GI->getName().empty())
192192 symbols.push_back(GI->getName());
193193
194194 // Loop over functions
195195 for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
196 if (!FI->isDeclaration() && !FI->hasInternalLinkage())
196 if (!FI->isDeclaration() && !FI->hasLocalLinkage())
197197 if (!FI->getName().empty())
198198 symbols.push_back(FI->getName());
199199
452452 KEYWORD(declare); KEYWORD(define);
453453 KEYWORD(global); KEYWORD(constant);
454454
455 KEYWORD(private);
455456 KEYWORD(internal);
456457 KEYWORD(linkonce);
457458 KEYWORD(weak);
112112 // optional leading prefixes, the production is:
113113 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
114114 // OptionalAddrSpace ('constant'|'global') ...
115 case lltok::kw_private: // OptionalLinkage
115116 case lltok::kw_internal: // OptionalLinkage
116117 case lltok::kw_weak: // OptionalLinkage
117118 case lltok::kw_linkonce: // OptionalLinkage
374375
375376 if (Linkage != GlobalValue::ExternalLinkage &&
376377 Linkage != GlobalValue::WeakLinkage &&
377 Linkage != GlobalValue::InternalLinkage)
378 Linkage != GlobalValue::InternalLinkage &&
379 Linkage != GlobalValue::PrivateLinkage)
378380 return Error(LinkageLoc, "invalid linkage type for alias");
379381
380382 Constant *Aliasee;
737739
738740 /// ParseOptionalLinkage
739741 /// ::= /*empty*/
742 /// ::= 'private'
740743 /// ::= 'internal'
741744 /// ::= 'weak'
742745 /// ::= 'linkonce'
750753 HasLinkage = false;
751754 switch (Lex.getKind()) {
752755 default: Res = GlobalValue::ExternalLinkage; return false;
756 case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
753757 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
754758 case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break;
755759 case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break;
20642068 if (isDefine)
20652069 return Error(LinkageLoc, "invalid linkage for function definition");
20662070 break;
2071 case GlobalValue::PrivateLinkage:
20672072 case GlobalValue::InternalLinkage:
20682073 case GlobalValue::LinkOnceLinkage:
20692074 case GlobalValue::WeakLinkage:
3535 kw_declare, kw_define,
3636 kw_global, kw_constant,
3737
38 kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
38 kw_private, kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
3939 kw_dllexport, kw_common, kw_default, kw_hidden, kw_protected,
4040 kw_extern_weak,
4141 kw_external, kw_thread_local,
6666 case 6: return GlobalValue::DLLExportLinkage;
6767 case 7: return GlobalValue::ExternalWeakLinkage;
6868 case 8: return GlobalValue::CommonLinkage;
69 case 9: return GlobalValue::PrivateLinkage;
6970 }
7071 }
7172
283283 case GlobalValue::DLLExportLinkage: return 6;
284284 case GlobalValue::ExternalWeakLinkage: return 7;
285285 case GlobalValue::CommonLinkage: return 8;
286 case GlobalValue::PrivateLinkage: return 9;
286287 }
287288 }
288289
138138 }
139139
140140 bool AsmPrinter::doInitialization(Module &M) {
141 Mang = new Mangler(M, TAI->getGlobalPrefix());
141 Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix());
142142
143143 GCModuleInfo *MI = getAnalysisToUpdate();
144144 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
198198 O << "\t.globl\t" << Name << '\n';
199199 else if (I->hasWeakLinkage())
200200 O << TAI->getWeakRefDirective() << Name << '\n';
201 else if (!I->hasInternalLinkage())
201 else if (!I->hasLocalLinkage())
202202 assert(0 && "Invalid alias linkage");
203203
204204 printVisibility(Name, I->getVisibility());
32713271 // Externally visible entry into the functions eh frame info.
32723272 // If the corresponding function is static, this should not be
32733273 // externally visible.
3274 if (linkage != Function::InternalLinkage) {
3274 if (linkage != Function::InternalLinkage &&
3275 linkage != Function::PrivateLinkage) {
32753276 if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
32763277 O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
32773278 }
173173 case GlobalValue::WeakLinkage:
174174 FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK);
175175 break;
176 case GlobalValue::PrivateLinkage:
177 assert (0 && "PrivateLinkage should not be in the symbol table.");
176178 case GlobalValue::InternalLinkage:
177179 FnSym.SetBind(ELFWriter::ELFSym::STB_LOCAL);
178180 break;
328330
329331 // Set the idx of the .bss section
330332 BSSSym.SectionIdx = BSSSection.SectionIdx;
331 SymbolTable.push_back(BSSSym);
333 if (!GV->hasPrivateLinkage())
334 SymbolTable.push_back(BSSSym);
332335
333336 // Reserve space in the .bss section for this symbol.
334337 BSSSection.Size += Size;
370370 SecDataOut.outbyte(0);
371371 }
372372 // Globals without external linkage apparently do not go in the symbol table.
373 if (GV->getLinkage() != GlobalValue::InternalLinkage) {
373 if (!GV->hasLocalLinkage()) {
374374 MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TM);
375375 Sym.n_value = Sec->size;
376376 SymbolTable.push_back(Sym);
958958 GVName = TAI->getGlobalPrefix() + name;
959959 n_type |= GV->hasHiddenVisibility() ? N_PEXT : N_EXT;
960960 break;
961 case GlobalValue::PrivateLinkage:
962 GVName = TAI->getPrivateGlobalPrefix() + name;
963 break;
961964 case GlobalValue::InternalLinkage:
962965 GVName = TAI->getGlobalPrefix() + name;
963966 break;
42754275 // Check for well-known libc/libm calls. If the function is internal, it
42764276 // can't be a library call.
42774277 unsigned NameLen = F->getNameLen();
4278 if (!F->hasInternalLinkage() && NameLen) {
4278 if (!F->hasLocalLinkage() && NameLen) {
42794279 const char *NameStr = F->getNameStart();
42804280 if (NameStr[0] == 'c' &&
42814281 ((NameLen == 8 && !strcmp(NameStr, "copysign")) ||
248248 // an old-style (llvmgcc3) static ctor with __main linked in and in use. If
249249 // this is the case, don't execute any of the global ctors, __main will do
250250 // it.
251 if (!GV || GV->isDeclaration() || GV->hasInternalLinkage()) return;
251 if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
252252
253253 // Should be an array of '{ int, void ()* }' structs. The first value is
254254 // the init priority, which we ignore.
892892 for (Module::const_global_iterator I = M.global_begin(),
893893 E = M.global_end(); I != E; ++I) {
894894 const GlobalValue *GV = I;
895 if (GV->hasInternalLinkage() || GV->isDeclaration() ||
895 if (GV->hasLocalLinkage() || GV->isDeclaration() ||
896896 GV->hasAppendingLinkage() || !GV->hasName())
897897 continue;// Ignore external globals and globals with internal linkage.
898898
553553 addGlobalMapping(GV, Ptr);
554554 }
555555 } else {
556 if (isGVCompilationDisabled() && !GV->hasInternalLinkage()) {
556 if (isGVCompilationDisabled() && !GV->hasLocalLinkage()) {
557557 cerr << "Compilation of non-internal GlobalValue is disabled!\n";
558558 abort();
559559 }
4949 if (I->hasName()) {
5050 if (I->isDeclaration())
5151 UndefinedSymbols.insert(I->getName());
52 else if (!I->hasInternalLinkage()) {
52 else if (!I->hasLocalLinkage()) {
5353 assert(!I->hasDLLImportLinkage()
5454 && "Found dllimported non-external symbol!");
5555 DefinedSymbols.insert(I->getName());
6161 if (I->hasName()) {
6262 if (I->isDeclaration())
6363 UndefinedSymbols.insert(I->getName());
64 else if (!I->hasInternalLinkage()) {
64 else if (!I->hasLocalLinkage()) {
6565 assert(!I->hasDLLImportLinkage()
6666 && "Found dllimported non-external symbol!");
6767 DefinedSymbols.insert(I->getName());
None //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
0 //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
414414
415415 // If there is a conflict, rename the conflict.
416416 if (GlobalValue *ConflictGV = cast_or_null(ST.lookup(Name))) {
417 assert(ConflictGV->hasInternalLinkage() &&
417 assert(ConflictGV->hasLocalLinkage() &&
418418 "Not conflicting with a static global, should link instead!");
419419 GV->takeName(ConflictGV);
420420 ConflictGV->setName(Name); // This will cause ConflictGV to get renamed
443443 static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
444444 GlobalValue::LinkageTypes <, bool &LinkFromSrc,
445445 std::string *Err) {
446 assert((!Dest || !Src->hasInternalLinkage()) &&
446 assert((!Dest || !Src->hasLocalLinkage()) &&
447447 "If Src has internal linkage, Dest shouldn't be set!");
448448 if (!Dest) {
449449 // Linking something to nothing.
535535
536536 // Check to see if may have to link the global with the global, alias or
537537 // function.
538 if (SGV->hasName() && !SGV->hasInternalLinkage())
538 if (SGV->hasName() && !SGV->hasLocalLinkage())
539539 DGV = cast_or_null(DestSymTab.lookup(SGV->getNameStart(),
540540 SGV->getNameEnd()));
541541
542542 // If we found a global with the same name in the dest module, but it has
543543 // internal linkage, we are really not doing any linkage here.
544 if (DGV && DGV->hasInternalLinkage())
544 if (DGV && DGV->hasLocalLinkage())
545545 DGV = 0;
546546
547547 // If types don't agree due to opaque types, try to resolve them.
572572 // If the LLVM runtime renamed the global, but it is an externally visible
573573 // symbol, DGV must be an existing global with internal linkage. Rename
574574 // it.
575 if (!NewDGV->hasInternalLinkage() && NewDGV->getName() != SGV->getName())
575 if (!NewDGV->hasLocalLinkage() && NewDGV->getName() != SGV->getName())
576576 ForceRenaming(NewDGV, SGV->getName());
577577
578578 // Make sure to remember this mapping.
642642
643643 // If the symbol table renamed the global, but it is an externally visible
644644 // symbol, DGV must be an existing global with internal linkage. Rename.
645 if (NewDGV->getName() != SGV->getName() && !NewDGV->hasInternalLinkage())
645 if (NewDGV->getName() != SGV->getName() && !NewDGV->hasLocalLinkage())
646646 ForceRenaming(NewDGV, SGV->getName());
647647
648648 // Inherit const as appropriate.
686686 return GlobalValue::ExternalLinkage;
687687 else if (SGV->hasWeakLinkage() || DGV->hasWeakLinkage())
688688 return GlobalValue::WeakLinkage;
689 else if (SGV->hasInternalLinkage() && DGV->hasInternalLinkage())
690 return GlobalValue::InternalLinkage;
689691 else {
690 assert(SGV->hasInternalLinkage() && DGV->hasInternalLinkage() &&
691 "Unexpected linkage type");
692 return GlobalValue::InternalLinkage;
692 assert (SGV->hasPrivateLinkage() && DGV->hasPrivateLinkage() &&
693 "Unexpected linkage type");
694 return GlobalValue::PrivateLinkage;
693695 }
694696 }
695697
714716 GlobalValue* DGV = NULL;
715717
716718 // Try to find something 'similar' to SGA in destination module.
717 if (!DGV && !SGA->hasInternalLinkage()) {
719 if (!DGV && !SGA->hasLocalLinkage()) {
718720 DGV = Dest->getNamedAlias(SGA->getName());
719721
720722 // If types don't agree due to opaque types, try to resolve them.
722724 RecursiveResolveTypes(SGA->getType(), DGV->getType());
723725 }
724726
725 if (!DGV && !SGA->hasInternalLinkage()) {
727 if (!DGV && !SGA->hasLocalLinkage()) {
726728 DGV = Dest->getGlobalVariable(SGA->getName());
727729
728730 // If types don't agree due to opaque types, try to resolve them.
730732 RecursiveResolveTypes(SGA->getType(), DGV->getType());
731733 }
732734
733 if (!DGV && !SGA->hasInternalLinkage()) {
735 if (!DGV && !SGA->hasLocalLinkage()) {
734736 DGV = Dest->getFunction(SGA->getName());
735737
736738 // If types don't agree due to opaque types, try to resolve them.
739741 }
740742
741743 // No linking to be performed on internal stuff.
742 if (DGV && DGV->hasInternalLinkage())
744 if (DGV && DGV->hasLocalLinkage())
743745 DGV = NULL;
744746
745747 if (GlobalAlias *DGA = dyn_cast_or_null(DGV)) {
830832 // If the symbol table renamed the alias, but it is an externally visible
831833 // symbol, DGA must be an global value with internal linkage. Rename it.
832834 if (NewGA->getName() != SGA->getName() &&
833 !NewGA->hasInternalLinkage())
835 !NewGA->hasLocalLinkage())
834836 ForceRenaming(NewGA, SGA->getName());
835837
836838 // Remember this mapping so uses in the source module get remapped
911913
912914 // Check to see if may have to link the function with the global, alias or
913915 // function.
914 if (SF->hasName() && !SF->hasInternalLinkage())
916 if (SF->hasName() && !SF->hasLocalLinkage())
915917 DGV = cast_or_null(DestSymTab.lookup(SF->getNameStart(),
916918 SF->getNameEnd()));
917919
918920 // If we found a global with the same name in the dest module, but it has
919921 // internal linkage, we are really not doing any linkage here.
920 if (DGV && DGV->hasInternalLinkage())
922 if (DGV && DGV->hasLocalLinkage())
921923 DGV = 0;
922924
923925 // If types don't agree due to opaque types, try to resolve them.
942944 // If the LLVM runtime renamed the function, but it is an externally
943945 // visible symbol, DF must be an existing function with internal linkage.
944946 // Rename it.
945 if (!NewDF->hasInternalLinkage() && NewDF->getName() != SF->getName())
947 if (!NewDF->hasLocalLinkage() && NewDF->getName() != SF->getName())
946948 ForceRenaming(NewDF, SF->getName());
947949
948950 // ... and remember this mapping...
981983 // If the symbol table renamed the function, but it is an externally
982984 // visible symbol, DF must be an existing function with internal
983985 // linkage. Rename it.
984 if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage())
986 if (NewDF->getName() != SF->getName() && !NewDF->hasLocalLinkage())
985987 ForceRenaming(NewDF, SF->getName());
986988
987989 // Remember this mapping so uses in the source module get remapped
807807 GlobalValue *GV = cast(Op)->getGlobal();
808808 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
809809 if (RelocM == Reloc::PIC_) {
810 bool UseGOTOFF = GV->hasInternalLinkage() || GV->hasHiddenVisibility();
810 bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
811811 ARMConstantPoolValue *CPV =
812812 new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
813813 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
196196 const Function *F = MF.getFunction();
197197 switch (F->getLinkage()) {
198198 default: assert(0 && "Unknown linkage type!");
199 case Function::PrivateLinkage:
199200 case Function::InternalLinkage:
200201 SwitchToTextSection("\t.text", F);
201202 break;
846847 }
847848 }
848849
849 if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
850 if (GVar->hasLocalLinkage() || GVar->mayBeOverridden()) {
850851 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
851852
852853 if (isDarwin) {
853 if (GVar->hasInternalLinkage()) {
854 if (GVar->hasLocalLinkage()) {
854855 O << TAI->getLCOMMDirective() << name << "," << Size
855856 << ',' << Align;
856857 } else if (GVar->hasCommonLinkage()) {
868869 return;
869870 }
870871 } else if (TAI->getLCOMMDirective() != NULL) {
871 if (GVar->hasInternalLinkage()) {
872 if (GVar->hasLocalLinkage()) {
872873 O << TAI->getLCOMMDirective() << name << "," << Size;
873874 } else {
874875 O << TAI->getCOMMDirective() << name << "," << Size;
877878 }
878879 } else {
879880 SwitchToSection(TAI->SectionForGlobal(GVar));
880 if (GVar->hasInternalLinkage())
881 if (GVar->hasLocalLinkage())
881882 O << "\t.local\t" << name << "\n";
882883 O << TAI->getCOMMDirective() << name << "," << Size;
883884 if (TAI->getCOMMDirectiveTakesAlignment())
908909 case GlobalValue::ExternalLinkage:
909910 O << "\t.globl " << name << "\n";
910911 // FALL THROUGH
912 case GlobalValue::PrivateLinkage:
911913 case GlobalValue::InternalLinkage:
912914 break;
913915 default:
512512 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
513513
514514 // if (!GV->hasWeakLinkage() && !GV->isDeclaration() && !GV->hasLinkOnceLinkage()) {
515 if (GV->hasInternalLinkage()) {
515 if (GV->hasLocalLinkage()) {
516516 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, GA,
517517 DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i64));
518518 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
168168
169169 O << "\t.ent " << CurrentFnName << "\n";
170170
171 assert (!F->hasPrivateLinkage() && "add private prefix.");
171172 O << CurrentFnName << ":\n";
172173
173174 // Print out code for the function.
19091909 if (getGlobalVariableClass(I))
19101910 continue;
19111911
1912 if (I->hasInternalLinkage())
1912 if (I->hasLocalLinkage())
19131913 Out << "static ";
19141914 else
19151915 Out << "extern ";
19451945 if (getGlobalVariableClass(I))
19461946 continue;
19471947
1948 if (I->hasInternalLinkage())
1948 if (I->hasLocalLinkage())
19491949 Out << "static ";
19501950 else if (I->hasDLLImportLinkage())
19511951 Out << "__declspec(dllimport) ";
21892189 /// isStructReturn - Should this function actually return a struct by-value?
21902190 bool isStructReturn = F->hasStructRetAttr();
21912191
2192 if (F->hasInternalLinkage()) Out << "static ";
2192 if (F->hasLocalLinkage()) Out << "static ";
21932193 if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
21942194 if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";
21952195 switch (F->getCallingConv()) {
441441
442442 switch (F->getLinkage()) {
443443 default: assert(0 && "Unknown linkage type!");
444 case Function::PrivateLinkage:
444445 case Function::InternalLinkage: // Symbols default to internal.
445446 break;
446447 case Function::ExternalLinkage:
535536
536537 if (C->isNullValue() && /* FIXME: Verify correct */
537538 !GVar->hasSection() &&
538 (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
539 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
539540 GVar->mayBeOverridden())) {
540541 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
541542
544545 O << "\t.type " << name << ", @object\n";
545546 O << name << ":\n";
546547 O << "\t.zero " << Size << '\n';
547 } else if (GVar->hasInternalLinkage()) {
548 } else if (GVar->hasLocalLinkage()) {
548549 O << TAI->getLCOMMDirective() << name << ',' << Size;
549550 } else {
550551 O << ".comm " << name << ',' << Size;
572573 O << "\t.global " << name << '\n'
573574 << "\t.type " << name << ", @object\n";
574575 // FALL THROUGH
576 case GlobalValue::PrivateLinkage:
575577 case GlobalValue::InternalLinkage:
576578 break;
577579 default:
616618 SPUTargetMachine &tm) {
617619 return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
618620 }
619
291291 switch (LT) {
292292 case GlobalValue::InternalLinkage:
293293 Out << "GlobalValue::InternalLinkage"; break;
294 case GlobalValue::PrivateLinkage:
295 Out << "GlobalValue::PrivateLinkage"; break;
294296 case GlobalValue::LinkOnceLinkage:
295297 Out << "GlobalValue::LinkOnceLinkage "; break;
296298 case GlobalValue::WeakLinkage:
6060 Mangler *Mang) const {
6161 if (GV==0)
6262 return false;
63 if (GV->hasInternalLinkage() && !isa(GV) &&
63 if (GV->hasLocalLinkage() && !isa(GV) &&
6464 ((strlen(getPrivateGlobalPrefix()) != 0 &&
6565 Mang->getValueName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
6666 getPrivateGlobalPrefix()) ||
4343 if (const Function *F = dyn_cast(GV)) {
4444 switch (F->getLinkage()) {
4545 default: assert(0 && "Unknown linkage type!");
46 case Function::PrivateLinkage:
4647 case Function::InternalLinkage:
4748 case Function::DLLExportLinkage:
4849 case Function::ExternalLinkage:
183184
184185 return Flags;
185186 }
186
274274
275275 if (C->isNullValue() && !GVar->hasSection()) {
276276 if (!GVar->isThreadLocal() &&
277 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
277 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
278278 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
279279
280 if (GVar->hasInternalLinkage()) {
280 if (GVar->hasLocalLinkage()) {
281281 O << "\t.lcomm " << name << "#," << Size
282282 << ',' << (1 << Align);
283283 O << '\n';
306306 O << TAI->getGlobalDirective() << name << '\n';
307307 // FALL THROUGH
308308 case GlobalValue::InternalLinkage:
309 case GlobalValue::PrivateLinkage:
309310 break;
310311 case GlobalValue::GhostLinkage:
311312 cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
348348 return ArgumentVT;
349349 // Function
350350 else if (const Function* F = dyn_cast(V))
351 return F->hasInternalLinkage() ? InternalVT : GlobalVT;
351 return F->hasLocalLinkage() ? InternalVT : GlobalVT;
352352 // Variable
353353 else if (const GlobalVariable* G = dyn_cast(V))
354 return G->hasInternalLinkage() ? InternalVT : GlobalVT;
354 return G->hasLocalLinkage() ? InternalVT : GlobalVT;
355355 // Constant
356356 else if (isa(V))
357357 return isa(V) ? ConstExprVT : ConstVT;
14001400 void MSILWriter::printFunction(const Function& F) {
14011401 bool isSigned = F.paramHasAttr(0, Attribute::SExt);
14021402 Out << "\n.method static ";
1403 Out << (F.hasInternalLinkage() ? "private " : "public ");
1403 Out << (F.hasLocalLinkage() ? "private " : "public ");
14041404 if (F.isVarArg()) Out << "vararg ";
14051405 Out << getTypeName(F.getReturnType(),isSigned) <<
14061406 getConvModopt(F.getCallingConv()) << getValueName(&F) << '\n';
273273 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
274274
275275 O << "\n\n";
276
277 // What's my mangled name?
278 CurrentFnName = Mang->getValueName(MF.getFunction());
279276
280277 // Emit the function start directives
281278 emitFunctionStart(MF);
383380 return;
384381
385382 case MachineOperand::MO_GlobalAddress:
386 O << Mang->getValueName(MO.getGlobal());
383 {
384 const GlobalValue *GV = MO.getGlobal();
385 O << Mang->getValueName(GV);
386 }
387387 break;
388388
389389 case MachineOperand::MO_ExternalSymbol:
448448 bool MipsAsmPrinter::
449449 doInitialization(Module &M)
450450 {
451 Mang = new Mangler(M);
451 Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
452452
453453 // Tell the assembler which ABI we are using
454454 O << "\t.section .mdebug." << emitCurrentABIString() << '\n';
501501
502502 if (C->isNullValue() && !GVar->hasSection()) {
503503 if (!GVar->isThreadLocal() &&
504 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
504 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
505505 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
506506
507 if (GVar->hasInternalLinkage())
507 if (GVar->hasLocalLinkage())
508508 O << "\t.local\t" << name << '\n';
509509
510510 O << TAI->getCOMMDirective() << name << ',' << Size;
530530 // If external or appending, declare as a global symbol
531531 O << TAI->getGlobalDirective() << name << '\n';
532532 // Fall Through
533 case GlobalValue::PrivateLinkage:
533534 case GlobalValue::InternalLinkage:
534535 if (CVA && CVA->isCString())
535536 printSizeAndType = false;
215215
216216 // if this is a internal constant string, there is a special
217217 // section for it, but not in small data/bss.
218 if (GVA->hasInitializer() && GV->hasInternalLinkage()) {
218 if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
219219 Constant *C = GVA->getInitializer();
220220 const ConstantArray *CVA = dyn_cast(C);
221221 if (CVA && CVA->isCString())
488488 SDValue ResNode = DAG.getLoad(MVT::i32, DAG.getEntryNode(), GA, NULL, 0);
489489 // On functions and global targets not internal linked only
490490 // a load from got/GP is necessary for PIC to work.
491 if (!GV->hasInternalLinkage() || isa(GV))
491 if (!GV->hasLocalLinkage() || isa(GV))
492492 return ResNode;
493493 SDValue Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA);
494494 return DAG.getNode(ISD::ADD, MVT::i32, ResNode, Lo);
583583
584584 switch (F->getLinkage()) {
585585 default: assert(0 && "Unknown linkage type!");
586 case Function::PrivateLinkage:
586587 case Function::InternalLinkage: // Symbols default to internal.
587588 break;
588589 case Function::ExternalLinkage:
685686
686687 if (C->isNullValue() && /* FIXME: Verify correct */
687688 !GVar->hasSection() &&
688 (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
689 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
689690 GVar->mayBeOverridden())) {
690691 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
691692
694695 O << "\t.type " << name << ", @object\n";
695696 O << name << ":\n";
696697 O << "\t.zero " << Size << '\n';
697 } else if (GVar->hasInternalLinkage()) {
698 } else if (GVar->hasLocalLinkage()) {
698699 O << TAI->getLCOMMDirective() << name << ',' << Size;
699700 } else {
700701 O << ".comm " << name << ',' << Size;
722723 << "\t.type " << name << ", @object\n";
723724 // FALL THROUGH
724725 case GlobalValue::InternalLinkage:
726 case GlobalValue::PrivateLinkage:
725727 break;
726728 default:
727729 cerr << "Unknown linkage type!";
910912
911913 if (C->isNullValue() && /* FIXME: Verify correct */
912914 !GVar->hasSection() &&
913 (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
915 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
914916 GVar->mayBeOverridden())) {
915917 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
916918
918920 O << "\t.globl " << name << '\n';
919921 O << "\t.zerofill __DATA, __common, " << name << ", "
920922 << Size << ", " << Align;
921 } else if (GVar->hasInternalLinkage()) {
923 } else if (GVar->hasLocalLinkage()) {
922924 O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
923925 } else if (!GVar->hasCommonLinkage()) {
924926 O << "\t.globl " << name << '\n'
9797 static unsigned BBNumber = 0;
9898
9999 O << "\n\n";
100 // What's my mangled name?
101 CurrentFnName = Mang->getValueName(MF.getFunction());
102100
103101 // Print out the label for the function.
104102 const Function *F = MF.getFunction();
167165 printBasicBlockLabel(MO.getMBB());
168166 return;
169167 case MachineOperand::MO_GlobalAddress:
170 O << Mang->getValueName(MO.getGlobal());
168 {
169 const GlobalValue *GV = MO.getGlobal();
170 O << Mang->getValueName(GV);
171 }
171172 break;
172173 case MachineOperand::MO_ExternalSymbol:
173174 O << MO.getSymbolName();
217218 }
218219
219220 bool SparcAsmPrinter::doInitialization(Module &M) {
220 Mang = new Mangler(M);
221 Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
221222 return false; // success
222223 }
223224
254255
255256 if (C->isNullValue() && !GVar->hasSection()) {
256257 if (!GVar->isThreadLocal() &&
257 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
258 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
258259 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
259260
260 if (GVar->hasInternalLinkage())
261 if (GVar->hasLocalLinkage())
261262 O << "\t.local " << name << '\n';
262263
263264 O << TAI->getCOMMDirective() << name << ',' << Size;
283284 // If external or appending, declare as a global symbol
284285 O << TAI->getGlobalDirective() << name << '\n';
285286 // FALL THROUGH
287 case GlobalValue::PrivateLinkage:
286288 case GlobalValue::InternalLinkage:
287289 break;
288290 case GlobalValue::GhostLinkage:
158158 switch (F->getLinkage()) {
159159 default: assert(0 && "Unknown linkage type!");
160160 case Function::InternalLinkage: // Symbols default to internal.
161 case Function::PrivateLinkage:
161162 EmitAlignment(FnAlign, F);
162163 break;
163164 case Function::DLLExportLinkage:
187188 else if (Subtarget->isTargetCygMing()) {
188189 O << "\t.def\t " << CurrentFnName
189190 << ";\t.scl\t" <<
190 (F->getLinkage() == Function::InternalLinkage ? COFF::C_STAT : COFF::C_EXT)
191 (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
191192 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
192193 << ";\t.endef\n";
193194 }
420421 if (shouldPrintPLT(TM, Subtarget)) {
421422 // Assemble call via PLT for externally visible symbols
422423 if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
423 !GV->hasInternalLinkage())
424 !GV->hasLocalLinkage())
424425 O << "@PLT";
425426 }
426427 if (Subtarget->isTargetCygMing() && GV->isDeclaration())
788789 }
789790
790791 if (!GVar->isThreadLocal() &&
791 (GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
792 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
792793 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
793794
794795 if (TAI->getLCOMMDirective() != NULL) {
795 if (GVar->hasInternalLinkage()) {
796 if (GVar->hasLocalLinkage()) {
796797 O << TAI->getLCOMMDirective() << name << ',' << Size;
797798 if (Subtarget->isTargetDarwin())
798799 O << ',' << Align;
812813 }
813814 } else {
814815 if (!Subtarget->isTargetCygMing()) {
815 if (GVar->hasInternalLinkage())
816 if (GVar->hasLocalLinkage())
816817 O << "\t.local\t" << name << '\n';
817818 }
818819 O << TAI->getCOMMDirective() << name << ',' << Size;
848849 // If external or appending, declare as a global symbol
849850 O << "\t.globl " << name << '\n';
850851 // FALL THROUGH
852 case GlobalValue::PrivateLinkage:
851853 case GlobalValue::InternalLinkage:
852854 break;
853855 default:
144144 FnAlign = 1;
145145 switch (F->getLinkage()) {
146146 default: assert(0 && "Unsupported linkage type!");
147 case Function::PrivateLinkage:
147148 case Function::InternalLinkage:
148149 EmitAlignment(FnAlign);
149150 break;
5555 // Extra load is needed for all externally visible.
5656 if (isDirectCall)
5757 return false;
58 if (GV->hasInternalLinkage() || GV->hasHiddenVisibility())
58 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
5959 return false;
6060 return true;
6161 } else if (isTargetCygMing() || isTargetWindows()) {
7878 // returns false.
7979 if (TM.getRelocationModel() == Reloc::PIC_)
8080 return !isDirectCall &&
81 (GV->hasInternalLinkage() || GV->hasExternalLinkage());
81 (GV->hasLocalLinkage() || GV->hasExternalLinkage());
8282 return false;
8383 }
8484
197197 }
198198 // FALL THROUGH
199199 case GlobalValue::InternalLinkage:
200 case GlobalValue::PrivateLinkage:
200201 break;
201202 case GlobalValue::GhostLinkage:
202203 cerr << "Should not have any unmaterialized functions!\n";
258259 switch (F->getLinkage()) {
259260 default: assert(0 && "Unknown linkage type!");
260261 case Function::InternalLinkage: // Symbols default to internal.
262 case Function::PrivateLinkage:
261263 break;
262264 case Function::ExternalLinkage:
263265 emitGlobalDirective(CurrentFnName);
297299
298300 // Print out jump tables referenced by the function
299301 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
300
301 // What's my mangled name?
302 CurrentFnName = Mang->getValueName(MF.getFunction());
303302
304303 // Emit the function start directives
305304 emitFunctionStart(MF);
366365 printBasicBlockLabel(MO.getMBB());
367366 break;
368367 case MachineOperand::MO_GlobalAddress:
369 O << Mang->getValueName(MO.getGlobal());
370 if (MO.getGlobal()->hasExternalWeakLinkage())
371 ExtWeakSymbols.insert(MO.getGlobal());
368 {
369 const GlobalValue *GV = MO.getGlobal();
370 O << Mang->getValueName(GV);
371 if (GV->hasExternalWeakLinkage())
372 ExtWeakSymbols.insert(GV);
373 }
372374 break;
373375 case MachineOperand::MO_ExternalSymbol:
374376 O << MO.getSymbolName();
113113 Function *F = CGN->getFunction();
114114
115115 // Make sure that it is local to this module.
116 if (!F || !F->hasInternalLinkage()) return false;
116 if (!F || !F->hasLocalLinkage()) return false;
117117
118118 // First check: see if there are any pointer arguments! If not, quick exit.
119119 SmallVector, 16> PointerArgs;
7171
7272 // If this GV is dead, remove it.
7373 GV->removeDeadConstantUsers();
74 if (GV->use_empty() && GV->hasInternalLinkage()) {
74 if (GV->use_empty() && GV->hasLocalLinkage()) {
7575 GV->eraseFromParent();
7676 continue;
7777 }
8585
8686 if (Slot == 0) { // Nope, add it to the map.
8787 Slot = GV;
88 } else if (GV->hasInternalLinkage()) { // Yup, this is a duplicate!
88 } else if (GV->hasLocalLinkage()) { // Yup, this is a duplicate!
8989 // Make all uses of the duplicate constant use the canonical version.
9090 Replacements.push_back(std::make_pair(GV, Slot));
9191 }
171171 /// llvm.vastart is never called, the varargs list is dead for the function.
172172 bool DAE::DeleteDeadVarargs(Function &Fn) {
173173 assert(Fn.getFunctionType()->isVarArg() && "Function isn't varargs!");
174 if (Fn.isDeclaration() || !Fn.hasInternalLinkage()) return false;
174 if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
175175
176176 // Ensure that the function is only directly called.
177177 for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ++I) {
423423 return;
424424 }
425425
426 if (!F.hasInternalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
426 if (!F.hasLocalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
427427 MarkLive(F);
428428 return;
429429 }
6262 I != E; ++I) {
6363 if (CallInst* callInst = dyn_cast(&*I)) {
6464 Function* Callee = callInst->getCalledFunction();
65 if (Callee && Callee->hasInternalLinkage())
65 if (Callee && Callee->hasLocalLinkage())
6666 Callee->setLinkage(GlobalValue::ExternalLinkage);
6767 }
6868 }
8484
8585 bool isolateGV(Module &M) {
8686 // Mark all globals internal
87 // FIXME: what should we do with private linkage?
8788 for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
8889 if (!I->isDeclaration()) {
8990 I->setLinkage(GlobalValue::InternalLinkage);
6262 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
6363 Changed |= RemoveUnusedGlobalValue(*I);
6464 // Functions with external linkage are needed if they have a body
65 if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
65 if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
6666 !I->isDeclaration())
6767 GlobalIsNeeded(I);
6868 }
7272 Changed |= RemoveUnusedGlobalValue(*I);
7373 // Externally visible & appending globals are needed, if they have an
7474 // initializer.
75 if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
75 if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
7676 !I->isDeclaration())
7777 GlobalIsNeeded(I);
7878 }
463463 if (!GlobalUsersSafeToSRA(GV))
464464 return 0;
465465
466 assert(GV->hasInternalLinkage() && !GV->isConstant());
466 assert(GV->hasLocalLinkage() && !GV->isConstant());
467467 Constant *Init = GV->getInitializer();
468468 const Type *Ty = Init->getType();
469469
18071807 for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
18081808 Function *F = FI++;
18091809 F->removeDeadConstantUsers();
1810 if (F->use_empty() && (F->hasInternalLinkage() ||
1810 if (F->use_empty() && (F->hasLocalLinkage() ||
18111811 F->hasLinkOnceLinkage())) {
18121812 M.getFunctionList().erase(F);
18131813 Changed = true;
18141814 ++NumFnDeleted;
1815 } else if (F->hasInternalLinkage()) {
1815 } else if (F->hasLocalLinkage()) {
18161816 if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
18171817 OnlyCalledDirectly(F)) {
18181818 // If this function has C calling conventions, is not a varargs
18421842 for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
18431843 GVI != E; ) {
18441844 GlobalVariable *GV = GVI++;
1845 if (!GV->isConstant() && GV->hasInternalLinkage() &&
1845 if (!GV->isConstant() && GV->hasLocalLinkage() &&
18461846 GV->hasInitializer())
18471847 Changed |= ProcessInternalGlobal(GV, GVI);
18481848 }
19811981 /// globals. This should be kept up to date with CommitValueTo.
19821982 static bool isSimpleEnoughPointerToCommit(Constant *C) {
19831983 if (GlobalVariable *GV = dyn_cast(C)) {
1984 if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
1984 if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
19851985 return false; // do not allow weak/linkonce/dllimport/dllexport linkage.
19861986 return !GV->isDeclaration(); // reject external globals.
19871987 }
19901990 if (CE->getOpcode() == Instruction::GetElementPtr &&
19911991 isa(CE->getOperand(0))) {
19921992 GlobalVariable *GV = cast(CE->getOperand(0));
1993 if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
1993 if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
19941994 return false; // do not allow weak/linkonce/dllimport/dllexport linkage.
19951995 return GV->hasInitializer() &&
19961996 ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE);
6262 if (!I->isDeclaration()) {
6363 // Delete any klingons.
6464 I->removeDeadConstantUsers();
65 if (I->hasInternalLinkage())
65 if (I->hasLocalLinkage())
6666 LocalChange |= PropagateConstantsIntoArguments(*I);
6767 Changed |= PropagateConstantReturn(*I);
6868 }
6767
6868 // If we inlined the last possible call site to the function, delete the
6969 // function body now.
70 if (Callee->use_empty() && Callee->hasInternalLinkage() &&
70 if (Callee->use_empty() && Callee->hasLocalLinkage() &&
7171 !SCCFunctions.count(Callee)) {
7272 DOUT << " -> Deleting dead function: " << Callee->getName() << "\n";
7373 CallGraphNode *CalleeNode = CG[Callee];
239239 if (DNR && DNR->count(F))
240240 continue;
241241
242 if ((F->hasLinkOnceLinkage() || F->hasInternalLinkage()) &&
242 if ((F->hasLinkOnceLinkage() || F->hasLocalLinkage()) &&
243243 F->use_empty()) {
244244
245245 // Remove any call graph edges from the function to its callees.
120120 bool Changed = false;
121121
122122 // Mark all functions not in the api as internal.
123 // FIXME: maybe use private linkage?
123124 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
124125 if (!I->isDeclaration() && // Function must be defined here
125 !I->hasInternalLinkage() && // Can't already have internal linkage
126 !I->hasLocalLinkage() && // Can't already have internal linkage
126127 !ExternalNames.count(I->getName())) {// Not marked to keep external?
127128 I->setLinkage(GlobalValue::InternalLinkage);
128129 // Remove a callgraph edge from the external node to this function.
148149
149150 // Mark all global variables with initializers that are not in the api as
150151 // internal as well.
152 // FIXME: maybe use private linkage?
151153 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
152154 I != E; ++I)
153 if (!I->isDeclaration() && !I->hasInternalLinkage() &&
155 if (!I->isDeclaration() && !I->hasLocalLinkage() &&
154156 !ExternalNames.count(I->getName())) {
155157 I->setLinkage(GlobalValue::InternalLinkage);
156158 Changed = true;
244244 Function *G = FnVec[j];
245245
246246 if (!F->mayBeOverridden()) {
247 if (G->hasInternalLinkage()) {
247 if (G->hasLocalLinkage()) {
248248 F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
249249 G->replaceAllUsesWith(F);
250250 G->eraseFromParent();
328328 if (F->isDeclaration() || F->isIntrinsic())
329329 continue;
330330
331 if (!F->hasInternalLinkage() && !F->hasExternalLinkage() &&
331 if (!F->hasLocalLinkage() && !F->hasExternalLinkage() &&
332332 !F->hasWeakLinkage())
333333 continue;
334334
9494 OnlyUsedBy(C->getOperand(i), C))
9595 Operands.insert(C->getOperand(i));
9696 if (GlobalVariable *GV = dyn_cast(C)) {
97 if (!GV->hasInternalLinkage()) return; // Don't delete non static globals.
97 if (!GV->hasLocalLinkage()) return; // Don't delete non static globals.
9898 GV->eraseFromParent();
9999 }
100100 else if (!isa(C))
113113 for (ValueSymbolTable::iterator VI = ST.begin(), VE = ST.end(); VI != VE; ) {
114114 Value *V = VI->getValue();
115115 ++VI;
116 if (!isa(V) || cast(V)->hasInternalLinkage()) {
116 if (!isa(V) || cast(V)->hasLocalLinkage()) {
117117 if (!PreserveDbgInfo || strncmp(V->getNameStart(), "llvm.dbg", 8))
118118 // Set name to "", removing from symbol table!
119119 V->setName("");
161161
162162 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
163163 I != E; ++I) {
164 if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
164 if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
165165 if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
166166 I->setName(""); // Internal symbols can't participate in linkage
167167 }
168168
169169 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
170 if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
170 if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
171171 if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
172172 I->setName(""); // Internal symbols can't participate in linkage
173173 StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
267267
268268 // llvm.dbg.compile_units and llvm.dbg.subprograms are marked as linkonce
269269 // but since we are removing all debug information, make them internal now.
270 // FIXME: Use private linkage maybe?
270271 if (Constant *C = M.getNamedGlobal("llvm.dbg.compile_units"))
271272 if (GlobalVariable *GV = dyn_cast(C))
272273 GV->setLinkage(GlobalValue::InternalLinkage);
298299 Constant *C = DeadConstants.back();
299300 DeadConstants.pop_back();
300301 if (GlobalVariable *GV = dyn_cast(C)) {
301 if (GV->hasInternalLinkage())
302 if (GV->hasLocalLinkage())
302303 RemoveDeadConstant(GV);
303304 }
304305 else
328329 bool StripNonDebugSymbols::runOnModule(Module &M) {
329330 return StripSymbolNames(M, true);
330331 }
331
8181 bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
8282 Function *F = CGN->getFunction();
8383
84 if (!F || F->isDeclaration() || !F->hasInternalLinkage())
84 if (!F || F->isDeclaration() || !F->hasLocalLinkage())
8585 return false;
8686
8787 // Make sure that function returns struct.
202202 /// and out of the specified function (which cannot have its address taken),
203203 /// this method must be called.
204204 void AddTrackedFunction(Function *F) {
205 assert(F->hasInternalLinkage() && "Can only track internal functions!");
205 assert(F->hasLocalLinkage() && "Can only track internal functions!");
206206 // Add an entry, F -> undef.
207207 if (const StructType *STy = dyn_cast(F->getReturnType())) {
208208 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
608608
609609 Function *F = I.getParent()->getParent();
610610 // If we are tracking the return value of this function, merge it in.
611 if (!F->hasInternalLinkage())
611 if (!F->hasLocalLinkage())
612612 return;
613613
614614 if (!TrackedRetVals.empty() && I.getNumOperands() == 1) {
11691169 // The common case is that we aren't tracking the callee, either because we
11701170 // are not doing interprocedural analysis or the callee is indirect, or is
11711171 // external. Handle these cases first.
1172 if (F == 0 || !F->hasInternalLinkage()) {
1172 if (F == 0 || !F->hasLocalLinkage()) {
11731173 CallOverdefined:
11741174 // Void return and not tracking callee, just bail.
11751175 if (I->getType() == Type::VoidTy) return;
16551655 // taken or that are external as overdefined.
16561656 //
16571657 for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
1658 if (!F->hasInternalLinkage() || AddressIsTaken(F)) {
1658 if (!F->hasLocalLinkage() || AddressIsTaken(F)) {
16591659 if (!F->isDeclaration())
16601660 Solver.MarkBlockExecutable(F->begin());
16611661 for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end();
16701670 // their addresses taken, we can propagate constants through them.
16711671 for (Module::global_iterator G = M.global_begin(), E = M.global_end();
16721672 G != E; ++G)
1673 if (!G->isConstant() && G->hasInternalLinkage() && !AddressIsTaken(G))
1673 if (!G->isConstant() && G->hasLocalLinkage() && !AddressIsTaken(G))
16741674 Solver.TrackValueOfGlobalVariable(G);
16751675
16761676 // Solve for constants.
129129
130130 // Inline
131131 if (InlineFunction(CS, NULL, TD)) {
132 if (Callee->use_empty() && Callee->hasInternalLinkage())
132 if (Callee->use_empty() && Callee->hasLocalLinkage())
133133 DeadFunctions.insert(Callee);
134134 Changed = true;
135135 CallSites.erase(CallSites.begin() + index);
198198 // If there is only one call of the function, and it has internal linkage,
199199 // make it almost guaranteed to be inlined.
200200 //
201 if (Callee->hasInternalLinkage() && Callee->hasOneUse())
201 if (Callee->hasLocalLinkage() && Callee->hasOneUse())
202202 InlineCost -= 15000;
203203
204204 // If this function uses the coldcc calling convention, prefer not to inline
11481148
11491149 static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) {
11501150 switch (LT) {
1151 case GlobalValue::PrivateLinkage: Out << "private "; break;
11511152 case GlobalValue::InternalLinkage: Out << "internal "; break;
11521153 case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
11531154 case GlobalValue::WeakLinkage: Out << "weak "; break;
146146 Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(GlobalID++);
147147 } else {
148148 Name = makeNameProper(GV->getName() + Suffix, Prefix);
149 std::string prefix;
150 if (GV->hasPrivateLinkage())
151 prefix = PrivatePrefix;
152 else
153 prefix = "";
154 Name = prefix + Name;
149155 }
150156
151157 return Name;
152158 }
153159
154 Mangler::Mangler(Module &M, const char *prefix)
155 : Prefix(prefix), UseQuotes(false), PreserveAsmNames(false),
156 Count(0), TypeCounter(0) {
160 Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
161 : Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false),
162 PreserveAsmNames(false), Count(0), TypeCounter(0) {
157163 std::fill(AcceptableChars, array_endof(AcceptableChars), 0);
158164
159165 // Letters and numbers are acceptable.
152152 }
153153
154154 // Okay, the function exists. Does it have externally visible linkage?
155 if (F->hasInternalLinkage()) {
155 if (F->hasLocalLinkage()) {
156156 // Clear the function's name.
157157 F->setName("");
158158 // Retry, now there won't be a conflict.
237237 /// symbol table. If it does not exist, return null. The type argument
238238 /// should be the underlying type of the global, i.e., it should not have
239239 /// the top-level PointerType, which represents the address of the global.
240 /// If AllowInternal is set to true, this function will return types that
241 /// have InternalLinkage. By default, these types are not returned.
240 /// If AllowLocal is set to true, this function will return types that
241 /// have an local. By default, these types are not returned.
242242 ///
243243 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
244 bool AllowInternal) const {
244 bool AllowLocal) const {
245245 if (Value *V = ValSymTab->lookup(Name)) {
246246 GlobalVariable *Result = dyn_cast(V);
247 if (Result && (AllowInternal || !Result->hasInternalLinkage()))
247 if (Result && (AllowLocal || !Result->hasLocalLinkage()))
248248 return Result;
249249 }
250250 return 0;
375375 return;
376376 }
377377 }
378
349349 GV.hasExternalWeakLinkage() ||
350350 GV.hasGhostLinkage() ||
351351 (isa(GV) &&
352 (GV.hasInternalLinkage() || GV.hasWeakLinkage())),
352 (GV.hasLocalLinkage() || GV.hasWeakLinkage())),
353353 "Global is external, but doesn't have external or dllimport or weak linkage!",
354354 &GV);
355355
383383 void Verifier::visitGlobalAlias(GlobalAlias &GA) {
384384 Assert1(!GA.getName().empty(),
385385 "Alias name cannot be empty!", &GA);
386 Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() ||
386 Assert1(GA.hasExternalLinkage() || GA.hasLocalLinkage() ||
387387 GA.hasWeakLinkage(),
388388 "Alias should have external or external weak linkage!", &GA);
389389 Assert1(GA.getAliasee(),
0 ; Test to make sure that the 'private' tag is not lost!
1 ;
2 ; RUN: llvm-as < %s | llvm-dis | grep private
3
4 declare void @foo()
5
6 define private void @foo() {
7 ret void
8 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -mtriple=arm-linux-gnueabi > %t
3 ; RUN: grep .Lfoo: %t
4 ; RUN: egrep bl.*\.Lfoo %t
5 ; RUN: grep .Lbaz: %t
6 ; RUN: grep long.*\.Lbaz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
21
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc > %t
3 ; RUN: grep .Lfoo: %t
4 ; RUN: grep call.*\.Lfoo %t
5 ; RUN: grep .Lbaz: %t
6 ; RUN: grep movl.*\.Lbaz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -march=cellspu > %t
3 ; RUN: grep .Lfoo: %t
4 ; RUN: grep brsl.*\.Lfoo %t
5 ; RUN: grep .Lbaz: %t
6 ; RUN: grep ila.*\.Lbaz %t
7
8
9 declare void @foo()
10
11 define private void @foo() {
12 ret void
13 }
14
15 @baz = private global i32 4;
16
17 define i32 @bar() {
18 call void @foo()
19 %1 = load i32* @baz, align 4
20 ret i32 %1
21 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -march=ia64 > %t
3 ; RUN: grep .foo: %t
4 ; RUN: grep br.call.sptk.*\.foo %t
5 ; RUN: grep .baz: %t
6 ; RUN: grep ltoff.*\.baz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -march=mips > %t
3 ; RUN: grep \\\$foo: %t
4 ; RUN: grep call.*\\\$foo %t
5 ; RUN: grep \\\$baz: %t
6 ; RUN: grep lw.*\\\$baz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu > %t
3 ; RUN: grep .Lfoo: %t
4 ; RUN: grep bl.*\.Lfoo %t
5 ; RUN: grep .Lbaz: %t
6 ; RUN: grep lis.*\.Lbaz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -march=sparc > %t
3 ; RUN: grep .foo: %t
4 ; RUN: grep call.*\.foo %t
5 ; RUN: grep .baz: %t
6 ; RUN: grep ld.*\.baz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lfoo:
3 ; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep call.*\.Lfoo
4 ; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lbaz:
5 ; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep movl.*\.Lbaz
6
7 declare void @foo()
8
9 define private void @foo() {
10 ret void
11 }
12
13 @baz = private global i32 4;
14
15 define i32 @bar() {
16 call void @foo()
17 %1 = load i32* @baz, align 4
18 ret i32 %1
19 }
0 ; Test to make sure that the 'private' is used correctly.
1 ;
2 ; RUN: llvm-as < %s | llc -march=xcore > %t
3 ; RUN: grep .Lfoo: %t
4 ; RUN: grep bl.*\.Lfoo %t
5 ; RUN: grep .Lbaz: %t
6 ; RUN: grep ldw.*\.Lbaz %t
7
8 declare void @foo()
9
10 define private void @foo() {
11 ret void
12 }
13
14 @baz = private global i32 4;
15
16 define i32 @bar() {
17 call void @foo()
18 %1 = load i32* @baz, align 4
19 ret i32 %1
20 }
198198 /// prune appropriate entries out of M1s list.
199199 static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
200200 GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
201 if (!GV || GV->isDeclaration() || GV->hasInternalLinkage() ||
201 if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
202202 !GV->use_empty()) return;
203203
204204 std::vector > M1Tors, M2Tors;
6767 }
6868
6969 static char TypeCharForSymbol(GlobalValue &GV) {
70 /* FIXME: what to do with private linkage? */
7071 if (GV.isDeclaration()) return 'U';
7172 if (GV.hasLinkOnceLinkage()) return 'C';
7273 if (GV.hasCommonLinkage()) return 'C';
9091 return;
9192 if ((TypeChar == 'U') && DefinedOnly)
9293 return;
93 if (GV.hasInternalLinkage () && ExternalOnly)
94 if (GV.hasLocalLinkage () && ExternalOnly)
9495 return;
9596 if (OutputFormat == posix) {
9697 std::cout << GV.getName () << " " << TypeCharForSymbol (GV) << " "