llvm.org GIT mirror llvm / 63b34cd
IR: Introduce local_unnamed_addr attribute. If a local_unnamed_addr attribute is attached to a global, the address is known to be insignificant within the module. It is distinct from the existing unnamed_addr attribute in that it only describes a local property of the module rather than a global property of the symbol. This attribute is intended to be used by the code generator and LTO to allow the linker to decide whether the global needs to be in the symbol table. It is possible to exclude a global from the symbol table if three things are true: - This attribute is present on every instance of the global (which means that the normal rule that the global must have a unique address can be broken without being observable by the program by performing comparisons against the global's address) - The global has linkonce_odr linkage (which means that each linkage unit must have its own copy of the global if it requires one, and the copy in each linkage unit must be the same) - It is a constant or a function (which means that the program cannot observe that the unique-address rule has been broken by writing to the global) Although this attribute could in principle be computed from the module contents, LTO clients (i.e. linkers) will normally need to be able to compute this property as part of symbol resolution, and it would be inefficient to materialize every module just to compute it. See: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html for earlier discussion. Part of the fix for PR27553. Differential Revision: http://reviews.llvm.org/D20348 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272709 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 4 years ago
55 changed file(s) with 420 addition(s) and 312 deletion(s). Raw diff Collapse all Expand all
730730 * ``initialexec``: code 3
731731 * ``localexec``: code 4
732732
733 * *unnamed_addr*: If present and non-zero, indicates that the variable has
734 ``unnamed_addr``
733 .. _bcunnamedaddr:
734
735 * *unnamed_addr*: If present, an encoding of the ``unnamed_addr`` attribute of this
736 variable:
737
738 * not ``unnamed_addr``: code 0
739 * ``unnamed_addr``: code 1
740 * ``local_unnamed_addr``: code 2
735741
736742 .. _bcdllstorageclass:
737743
790796 * *gc*: If present and nonzero, the 1-based garbage collector index in the table
791797 of `MODULE_CODE_GCNAME`_ entries.
792798
793 * *unnamed_addr*: If present and non-zero, indicates that the function has
794 ``unnamed_addr``
799 * *unnamed_addr*: If present, an encoding of the
800 :ref:`unnamed_addr` attribute of this function
795801
796802 * *prologuedata*: If non-zero, the value index of the prologue data for this function,
797803 plus 1.
829835 * *threadlocal*: If present, an encoding of the
830836 :ref:`thread local property` of the alias
831837
832 * *unnamed_addr*: If present and non-zero, indicates that the alias has
833 ``unnamed_addr``
838 * *unnamed_addr*: If present, an encoding of the
839 :ref:`unnamed_addr` attribute of this alias
834840
835841 MODULE_CODE_PURGEVALS Record
836842 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
588588 merged with a ``unnamed_addr`` constant, the result being a constant
589589 whose address is significant.
590590
591 If the ``local_unnamed_addr`` attribute is given, the address is known to
592 not be significant within the module.
593
591594 A global variable may be declared to reside in a target-specific
592595 numbered address space. For targets that support them, address spaces
593596 may affect how optimizations are performed and/or what target
627630 Syntax::
628631
629632 @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
630 [unnamed_addr] [AddrSpace] [ExternallyInitialized]
633 [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
634 [ExternallyInitialized]
631635 []
632636 [, section "name"] [, comdat [($name)]]
633637 [, align ] (, !name !N)*
674678 an opening curly brace, a list of basic blocks, and a closing curly brace.
675679
676680 LLVM function declarations consist of the "``declare``" keyword, an
677 optional :ref:`linkage type `, an optional :ref:`visibility
678 style `, an optional :ref:`DLL storage class `,
679 an optional :ref:`calling convention `,
680 an optional ``unnamed_addr`` attribute, a return type, an optional
681 :ref:`parameter attribute ` for the return type, a function
682 name, a possibly empty list of arguments, an optional alignment, an optional
683 :ref:`garbage collector name `, an optional :ref:`prefix `,
684 and an optional :ref:`prologue `.
681 optional :ref:`linkage type `, an optional :ref:`visibility style
682 `, an optional :ref:`DLL storage class `, an
683 optional :ref:`calling convention `, an optional ``unnamed_addr``
684 or ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter
685 attribute ` for the return type, a function name, a possibly
686 empty list of arguments, an optional alignment, an optional :ref:`garbage
687 collector name `, an optional :ref:`prefix `, and an optional
688 :ref:`prologue `.
685689
686690 A function definition contains a list of basic blocks, forming the CFG (Control
687691 Flow Graph) for the function. Each basic block may optionally start with a label
712716 If the ``unnamed_addr`` attribute is given, the address is known to not
713717 be significant and two identical functions can be merged.
714718
719 If the ``local_unnamed_addr`` attribute is given, the address is known to
720 not be significant within the module.
721
715722 Syntax::
716723
717724 define [linkage] [visibility] [DLLStorageClass]
718725 [cconv] [ret attrs]
719726 @ ([argument list])
720 [unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
721 [align N] [gc] [prefix Constant] [prologue Constant]
722 [personality Constant] (!name !N)* { ... }
727 [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"]
728 [comdat [($name)]] [align N] [gc] [prefix Constant]
729 [prologue Constant] [personality Constant] (!name !N)* { ... }
723730
724731 The argument list is a comma separated sequence of arguments where each
725732 argument is of the following form:
746753
747754 Syntax::
748755
749 @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [unnamed_addr] alias , * @
756 @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias , * @
750757
751758 The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
752759 ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
755762 Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
756763 the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
757764 to the same content.
765
766 If the ``local_unnamed_addr`` attribute is given, the address is known to
767 not be significant within the module.
758768
759769 Since aliases are only a second name, some restrictions apply, of which
760770 some can only be checked when producing an object file:
6969 LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
7070 : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps),
7171 ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility),
72 UnnamedAddr(0), DllStorageClass(DefaultStorageClass),
73 ThreadLocal(NotThreadLocal), IntID((Intrinsic::ID)0U), Parent(nullptr) {
72 UnnamedAddrVal(unsigned(UnnamedAddr::None)),
73 DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
74 IntID((Intrinsic::ID)0U), Parent(nullptr) {
7475 setName(Name);
7576 }
7677
7980 // them.
8081 unsigned Linkage : 4; // The linkage of this global
8182 unsigned Visibility : 2; // The visibility style of this global
82 unsigned UnnamedAddr : 1; // This value's address is not significant
83 unsigned UnnamedAddrVal : 2; // This value's address is not significant
8384 unsigned DllStorageClass : 2; // DLL storage class
8485
8586 unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is
8889
8990 private:
9091 // Give subclasses access to what otherwise would be wasted padding.
91 // (19 + 3 + 2 + 1 + 2 + 5) == 32.
92 // (19 + 4 + 2 + 2 + 2 + 3) == 32.
9293 unsigned SubClassData : GlobalValueSubClassDataBits;
9394
9495 friend class Constant;
152153
153154 unsigned getAlignment() const;
154155
155 bool hasUnnamedAddr() const { return UnnamedAddr; }
156 void setUnnamedAddr(bool Val) { UnnamedAddr = Val; }
156 enum class UnnamedAddr {
157 None,
158 Local,
159 Global,
160 };
161
162 bool hasGlobalUnnamedAddr() const {
163 return getUnnamedAddr() == UnnamedAddr::Global;
164 }
165
166 /// Returns true if this value's address is not significant in this module.
167 /// This attribute is intended to be used only by the code generator and LTO
168 /// to allow the linker to decide whether the global needs to be in the symbol
169 /// table. It should probably not be used in optimizations, as the value may
170 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
171 bool hasAtLeastLocalUnnamedAddr() const {
172 return getUnnamedAddr() != UnnamedAddr::None;
173 }
174
175 UnnamedAddr getUnnamedAddr() const {
176 return UnnamedAddr(UnnamedAddrVal);
177 }
178 void setUnnamedAddr(UnnamedAddr Val) { UnnamedAddrVal = unsigned(Val); }
179
180 static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B) {
181 if (A == UnnamedAddr::None || B == UnnamedAddr::None)
182 return UnnamedAddr::None;
183 if (A == UnnamedAddr::Local || B == UnnamedAddr::Local)
184 return UnnamedAddr::Local;
185 return UnnamedAddr::Global;
186 }
157187
158188 bool hasComdat() const { return getComdat() != nullptr; }
159189 Comdat *getComdat();
20852085 return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
20862086 if (const GlobalValue *GV = dyn_cast(V))
20872087 return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
2088 GV->hasProtectedVisibility() || GV->hasUnnamedAddr()) &&
2088 GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
20892089 !GV->isThreadLocal();
20902090 if (const Argument *A = dyn_cast(V))
20912091 return A->hasByValAttr();
512512 KEYWORD(hidden);
513513 KEYWORD(protected);
514514 KEYWORD(unnamed_addr);
515 KEYWORD(local_unnamed_addr);
515516 KEYWORD(externally_initialized);
516517 KEYWORD(extern_weak);
517518 KEYWORD(external);
428428 return false;
429429 }
430430
431 bool LLParser::ParseOptionalUnnamedAddr(
432 GlobalVariable::UnnamedAddr &UnnamedAddr) {
433 if (EatIfPresent(lltok::kw_unnamed_addr))
434 UnnamedAddr = GlobalValue::UnnamedAddr::Global;
435 else if (EatIfPresent(lltok::kw_local_unnamed_addr))
436 UnnamedAddr = GlobalValue::UnnamedAddr::Local;
437 else
438 UnnamedAddr = GlobalValue::UnnamedAddr::None;
439 return false;
440 }
441
431442 /// ParseUnnamedGlobal:
432443 /// OptionalVisibility (ALIAS | IFUNC) ...
433444 /// OptionalLinkage OptionalVisibility OptionalDLLStorageClass
454465 bool HasLinkage;
455466 unsigned Linkage, Visibility, DLLStorageClass;
456467 GlobalVariable::ThreadLocalMode TLM;
457 bool UnnamedAddr;
468 GlobalVariable::UnnamedAddr UnnamedAddr;
458469 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
459 ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
470 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
460471 return true;
461472
462473 if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
480491 bool HasLinkage;
481492 unsigned Linkage, Visibility, DLLStorageClass;
482493 GlobalVariable::ThreadLocalMode TLM;
483 bool UnnamedAddr;
494 GlobalVariable::UnnamedAddr UnnamedAddr;
484495 if (ParseToken(lltok::equal, "expected '=' in global variable") ||
485496 ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
486 ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
497 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
487498 return true;
488499
489500 if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
658669 ///
659670 /// Everything through OptionalUnnamedAddr has already been parsed.
660671 ///
661 bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc,
662 unsigned L, unsigned Visibility,
663 unsigned DLLStorageClass,
664 GlobalVariable::ThreadLocalMode TLM,
665 bool UnnamedAddr) {
672 bool LLParser::parseIndirectSymbol(
673 const std::string &Name, LocTy NameLoc, unsigned L, unsigned Visibility,
674 unsigned DLLStorageClass, GlobalVariable::ThreadLocalMode TLM,
675 GlobalVariable::UnnamedAddr UnnamedAddr) {
666676 bool IsAlias;
667677 if (Lex.getKind() == lltok::kw_alias)
668678 IsAlias = true;
798808 unsigned Linkage, bool HasLinkage,
799809 unsigned Visibility, unsigned DLLStorageClass,
800810 GlobalVariable::ThreadLocalMode TLM,
801 bool UnnamedAddr) {
811 GlobalVariable::UnnamedAddr UnnamedAddr) {
802812 if (!isValidVisibilityForLinkage(Visibility, Linkage))
803813 return Error(NameLoc,
804814 "symbol with local linkage must have default visibility");
45794589 std::string Section;
45804590 unsigned Alignment;
45814591 std::string GC;
4582 bool UnnamedAddr;
4592 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
45834593 LocTy UnnamedAddrLoc;
45844594 Constant *Prefix = nullptr;
45854595 Constant *Prologue = nullptr;
45874597 Comdat *C;
45884598
45894599 if (ParseArgumentList(ArgList, isVarArg) ||
4590 ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
4591 &UnnamedAddrLoc) ||
4600 ParseOptionalUnnamedAddr(UnnamedAddr) ||
45924601 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps, false,
45934602 BuiltinLoc) ||
45944603 (EatIfPresent(lltok::kw_section) &&
225225
226226 bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
227227 bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
228 bool parseOptionalUnnamedAddr(bool &UnnamedAddr) {
229 return ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr);
230 }
228 bool ParseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
231229 bool ParseOptionalAddrSpace(unsigned &AddrSpace);
232230 bool ParseOptionalParamAttrs(AttrBuilder &B);
233231 bool ParseOptionalReturnAttrs(AttrBuilder &B);
274272 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
275273 bool HasLinkage, unsigned Visibility,
276274 unsigned DLLStorageClass,
277 GlobalVariable::ThreadLocalMode TLM, bool UnnamedAddr);
275 GlobalVariable::ThreadLocalMode TLM,
276 GlobalVariable::UnnamedAddr UnnamedAddr);
278277 bool parseIndirectSymbol(const std::string &Name, LocTy Loc,
279278 unsigned Linkage, unsigned Visibility,
280279 unsigned DLLStorageClass,
281280 GlobalVariable::ThreadLocalMode TLM,
282 bool UnnamedAddr);
281 GlobalVariable::UnnamedAddr UnnamedAddr);
283282 bool parseComdat();
284283 bool ParseStandaloneMetadata();
285284 bool ParseNamedMetadata();
5959 kw_hidden,
6060 kw_protected,
6161 kw_unnamed_addr,
62 kw_local_unnamed_addr,
6263 kw_externally_initialized,
6364 kw_extern_weak,
6465 kw_external,
769769 case 2: return GlobalVariable::LocalDynamicTLSModel;
770770 case 3: return GlobalVariable::InitialExecTLSModel;
771771 case 4: return GlobalVariable::LocalExecTLSModel;
772 }
773 }
774
775 static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType(unsigned Val) {
776 switch (Val) {
777 default: // Map unknown to UnnamedAddr::None.
778 case 0: return GlobalVariable::UnnamedAddr::None;
779 case 1: return GlobalVariable::UnnamedAddr::Global;
780 case 2: return GlobalVariable::UnnamedAddr::Local;
772781 }
773782 }
774783
37903799 if (Record.size() > 7)
37913800 TLM = getDecodedThreadLocalMode(Record[7]);
37923801
3793 bool UnnamedAddr = false;
3802 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
37943803 if (Record.size() > 8)
3795 UnnamedAddr = Record[8];
3804 UnnamedAddr = getDecodedUnnamedAddrType(Record[8]);
37963805
37973806 bool ExternallyInitialized = false;
37983807 if (Record.size() > 9)
38273836 } else if (hasImplicitComdat(RawLinkage)) {
38283837 NewGV->setComdat(reinterpret_cast(1));
38293838 }
3839
38303840 break;
38313841 }
38323842 case bitc::MODULE_CODE_GLOBALVAR_ATTACHMENT: {
38843894 return error("Invalid ID");
38853895 Func->setGC(GCTable[Record[8] - 1]);
38863896 }
3887 bool UnnamedAddr = false;
3897 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
38883898 if (Record.size() > 9)
3889 UnnamedAddr = Record[9];
3899 UnnamedAddr = getDecodedUnnamedAddrType(Record[9]);
38903900 Func->setUnnamedAddr(UnnamedAddr);
38913901 if (Record.size() > 10 && Record[10] != 0)
38923902 FunctionPrologues.push_back(std::make_pair(Func, Record[10]-1));
39733983 if (OpNum != Record.size())
39743984 NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[OpNum++]));
39753985 if (OpNum != Record.size())
3976 NewGA->setUnnamedAddr(Record[OpNum++]);
3986 NewGA->setUnnamedAddr(getDecodedUnnamedAddrType(Record[OpNum++]));
39773987 ValueList.push_back(NewGA);
39783988 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
39793989 break;
995995 llvm_unreachable("Invalid selection kind");
996996 }
997997
998 static unsigned getEncodedUnnamedAddr(const GlobalValue &GV) {
999 switch (GV.getUnnamedAddr()) {
1000 case GlobalValue::UnnamedAddr::None: return 0;
1001 case GlobalValue::UnnamedAddr::Local: return 2;
1002 case GlobalValue::UnnamedAddr::Global: return 1;
1003 }
1004 llvm_unreachable("Invalid unnamed_addr");
1005 }
1006
9981007 void ModuleBitcodeWriter::writeComdats() {
9991008 SmallVector Vals;
10001009 for (const Comdat *C : VE.getComdats()) {
11561165 Vals.push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
11571166 if (GV.isThreadLocal() ||
11581167 GV.getVisibility() != GlobalValue::DefaultVisibility ||
1159 GV.hasUnnamedAddr() || GV.isExternallyInitialized() ||
1168 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1169 GV.isExternallyInitialized() ||
11601170 GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass ||
11611171 GV.hasComdat()) {
11621172 Vals.push_back(getEncodedVisibility(GV));
11631173 Vals.push_back(getEncodedThreadLocalMode(GV));
1164 Vals.push_back(GV.hasUnnamedAddr());
1174 Vals.push_back(getEncodedUnnamedAddr(GV));
11651175 Vals.push_back(GV.isExternallyInitialized());
11661176 Vals.push_back(getEncodedDLLStorageClass(GV));
11671177 Vals.push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
11871197 Vals.push_back(F.hasSection() ? SectionMap[F.getSection()] : 0);
11881198 Vals.push_back(getEncodedVisibility(F));
11891199 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1190 Vals.push_back(F.hasUnnamedAddr());
1200 Vals.push_back(getEncodedUnnamedAddr(F));
11911201 Vals.push_back(F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1)
11921202 : 0);
11931203 Vals.push_back(getEncodedDLLStorageClass(F));
12041214
12051215 // Emit the alias information.
12061216 for (const GlobalAlias &A : M.aliases()) {
1207 // ALIAS: [alias type, aliasee val#, linkage, visibility]
1217 // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass,
1218 // threadlocal, unnamed_addr]
12081219 Vals.push_back(VE.getTypeID(A.getValueType()));
12091220 Vals.push_back(A.getType()->getAddressSpace());
12101221 Vals.push_back(VE.getValueID(A.getAliasee()));
12121223 Vals.push_back(getEncodedVisibility(A));
12131224 Vals.push_back(getEncodedDLLStorageClass(A));
12141225 Vals.push_back(getEncodedThreadLocalMode(A));
1215 Vals.push_back(A.hasUnnamedAddr());
1226 Vals.push_back(getEncodedUnnamedAddr(A));
12161227 unsigned AbbrevToUse = 0;
12171228 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
12181229 Vals.clear();
622622 if (!GV->hasLinkOnceODRLinkage())
623623 return false;
624624
625 if (GV->hasUnnamedAddr())
625 // We assume that anyone who sets global unnamed_addr on a non-constant knows
626 // what they're doing.
627 if (GV->hasGlobalUnnamedAddr())
626628 return true;
627629
628630 // If it is a non constant variable, it needs to be uniqued across shared
632634 return false;
633635 }
634636
635 // An alias can point to a variable. We could try to resolve the alias to
636 // decide, but for now just don't hide them.
637 if (isa(GV))
638 return false;
639
640 // If we don't see every use, we have to be conservative and assume the value
641 // address is significant.
642 if (GV->getParent()->getMaterializer())
643 return false;
644
645 GlobalStatus GS;
646 if (GlobalStatus::analyzeGlobal(GV, GS))
647 return false;
648
649 return !GS.IsCompared;
637 return GV->hasAtLeastLocalUnnamedAddr();
650638 }
651639
652640 // FIXME: make this a proper option
10001000 // Global GOT equivalents are unnamed private globals with a constant
10011001 // pointer initializer to another global symbol. They must point to a
10021002 // GlobalVariable or Function, i.e., as GlobalValue.
1003 if (!GV->hasUnnamedAddr() || !GV->hasInitializer() || !GV->isConstant() ||
1003 if (!GV->hasGlobalUnnamedAddr() || !GV->hasInitializer() || !GV->isConstant() ||
10041004 !GV->isDiscardableIfUnused() || !dyn_cast(GV->getOperand(0)))
10051005 return false;
10061006
428428 const TargetMachine &TM) const {
429429 // We may only use a PLT-relative relocation to refer to unnamed_addr
430430 // functions.
431 if (!LHS->hasUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
431 if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
432432 return nullptr;
433433
434434 // Basic sanity checks.
143143 V.setLinkage(GlobalValue::ExternalLinkage);
144144 V.setVisibility(GlobalValue::HiddenVisibility);
145145 }
146 V.setUnnamedAddr(false);
146 V.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
147147 assert(!R.needsRenaming(V) && "Invalid global name.");
148148 }
149149
24252425 }
24262426 }
24272427
2428 static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA) {
2429 switch (UA) {
2430 case GlobalVariable::UnnamedAddr::None:
2431 return "";
2432 case GlobalVariable::UnnamedAddr::Local:
2433 return "local_unnamed_addr";
2434 case GlobalVariable::UnnamedAddr::Global:
2435 return "unnamed_addr";
2436 }
2437 }
2438
24282439 static void maybePrintComdat(formatted_raw_ostream &Out,
24292440 const GlobalObject &GO) {
24302441 const Comdat *C = GO.getComdat();
24572468 PrintVisibility(GV->getVisibility(), Out);
24582469 PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
24592470 PrintThreadLocalModel(GV->getThreadLocalMode(), Out);
2460 if (GV->hasUnnamedAddr())
2461 Out << "unnamed_addr ";
2471 StringRef UA = getUnnamedAddrEncoding(GV->getUnnamedAddr());
2472 if (!UA.empty())
2473 Out << UA << ' ';
24622474
24632475 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
24642476 Out << "addrspace(" << AddressSpace << ") ";
24982510 PrintVisibility(GIS->getVisibility(), Out);
24992511 PrintDLLStorageClass(GIS->getDLLStorageClass(), Out);
25002512 PrintThreadLocalModel(GIS->getThreadLocalMode(), Out);
2501 if (GIS->hasUnnamedAddr())
2502 Out << "unnamed_addr ";
2513 StringRef UA = getUnnamedAddrEncoding(GIS->getUnnamedAddr());
2514 if (!UA.empty())
2515 Out << UA << ' ';
25032516
25042517 if (isa(GIS))
25052518 Out << "alias ";
26552668 Out << "..."; // Output varargs portion of signature!
26562669 }
26572670 Out << ')';
2658 if (F->hasUnnamedAddr())
2659 Out << " unnamed_addr";
2671 StringRef UA = getUnnamedAddrEncoding(F->getUnnamedAddr());
2672 if (!UA.empty())
2673 Out << ' ' << UA;
26602674 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
26612675 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
26622676 if (F->hasSection()) {
15591559 }
15601560
15611561 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global) {
1562 return unwrap(Global)->hasUnnamedAddr();
1562 return unwrap(Global)->hasGlobalUnnamedAddr();
15631563 }
15641564
15651565 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1566 unwrap(Global)->setUnnamedAddr(HasUnnamedAddr);
1566 unwrap(Global)->setUnnamedAddr(
1567 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1568 : GlobalValue::UnnamedAddr::None);
15671569 }
15681570
15691571 /*--.. Operations on global variables, load and store instructions .........--*/
5050 /// create a GlobalValue) from the GlobalValue Src to this one.
5151 void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
5252 setVisibility(Src->getVisibility());
53 setUnnamedAddr(Src->hasUnnamedAddr());
53 setUnnamedAddr(Src->getUnnamedAddr());
5454 setDLLStorageClass(Src->getDLLStorageClass());
5555 }
5656
3333 StrConstant, Name, nullptr,
3434 GlobalVariable::NotThreadLocal,
3535 AddressSpace);
36 GV->setUnnamedAddr(true);
36 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
3737 return GV;
3838 }
3939
15341534 if (Attrs.hasAttribute(AttributeSet::FunctionIndex,
15351535 Attribute::JumpTable)) {
15361536 const GlobalValue *GV = cast(V);
1537 Assert(GV->hasUnnamedAddr(),
1537 Assert(GV->hasGlobalUnnamedAddr(),
15381538 "Attribute 'jumptable' requires 'unnamed_addr'", V);
15391539 }
15401540
790790 return stringErr(
791791 "Appending variables with different visibility need to be linked!");
792792
793 if (DstGV->hasUnnamedAddr() != SrcGV->hasUnnamedAddr())
793 if (DstGV->hasGlobalUnnamedAddr() != SrcGV->hasGlobalUnnamedAddr())
794794 return stringErr(
795795 "Appending variables with different unnamed_addr need to be linked!");
796796
376376 DGV->setVisibility(Visibility);
377377 GV.setVisibility(Visibility);
378378
379 bool HasUnnamedAddr = GV.hasUnnamedAddr() && DGV->hasUnnamedAddr();
380 DGV->setUnnamedAddr(HasUnnamedAddr);
381 GV.setUnnamedAddr(HasUnnamedAddr);
379 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::getMinUnnamedAddr(
380 DGV->getUnnamedAddr(), GV.getUnnamedAddr());
381 DGV->setUnnamedAddr(UnnamedAddr);
382 GV.setUnnamedAddr(UnnamedAddr);
382383 }
383384
384385 // Don't want to append to global_ctors list, for example, when we
693693 nullptr,
694694 GlobalVariable::NotThreadLocal,
695695 AMDGPUAS::LOCAL_ADDRESS);
696 GV->setUnnamedAddr(true);
696 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
697697 GV->setAlignment(I.getAlignment());
698698
699699 Value *TCntY, *TCntZ;
173173 // If the global is required to have a unique address, it can't be put
174174 // into a mergable section: just drop it into the general read-only
175175 // section instead.
176 if (!GVar->hasUnnamedAddr())
176 if (!GVar->hasGlobalUnnamedAddr())
177177 return SectionKind::getReadOnly();
178178
179179 // If initializer is a null-terminated string, put it in a "cstring"
5656 if (A.hasLocalLinkage() && !B.hasLocalLinkage())
5757 return false;
5858
59 return A.hasUnnamedAddr();
59 return A.hasGlobalUnnamedAddr();
6060 }
6161
6262 static unsigned getAlignment(GlobalVariable *GV) {
151151 if (!Slot || Slot == GV)
152152 continue;
153153
154 if (!Slot->hasUnnamedAddr() && !GV->hasUnnamedAddr())
155 continue;
156
157 if (!GV->hasUnnamedAddr())
158 Slot->setUnnamedAddr(false);
154 if (!Slot->hasGlobalUnnamedAddr() && !GV->hasGlobalUnnamedAddr())
155 continue;
156
157 if (!GV->hasGlobalUnnamedAddr())
158 Slot->setUnnamedAddr(GlobalValue::UnnamedAddr::None);
159159
160160 // Make all uses of the duplicate constant use the canonical version.
161161 Replacements.push_back(std::make_pair(GV, Slot));
19411941 static bool
19421942 processGlobal(GlobalValue &GV, TargetLibraryInfo *TLI,
19431943 function_ref LookupDomTree) {
1944 if (GV.getName().startswith("llvm."))
1945 return false;
1946
1947 GlobalStatus GS;
1948
1949 if (GlobalStatus::analyzeGlobal(&GV, GS))
1950 return false;
1951
1952 bool Changed = false;
1953 if (!GS.IsCompared && !GV.hasGlobalUnnamedAddr()) {
1954 auto NewUnnamedAddr = GV.hasLocalLinkage() ? GlobalValue::UnnamedAddr::Global
1955 : GlobalValue::UnnamedAddr::Local;
1956 if (NewUnnamedAddr != GV.getUnnamedAddr()) {
1957 GV.setUnnamedAddr(NewUnnamedAddr);
1958 NumUnnamed++;
1959 Changed = true;
1960 }
1961 }
1962
19441963 // Do more involved optimizations if the global is internal.
19451964 if (!GV.hasLocalLinkage())
1946 return false;
1947
1948 GlobalStatus GS;
1949
1950 if (GlobalStatus::analyzeGlobal(&GV, GS))
1951 return false;
1952
1953 bool Changed = false;
1954 if (!GS.IsCompared && !GV.hasUnnamedAddr()) {
1955 GV.setUnnamedAddr(true);
1956 NumUnnamed++;
1957 Changed = true;
1958 }
1965 return Changed;
19591966
19601967 auto *GVar = dyn_cast(&GV);
19611968 if (!GVar)
16361636
16371637 // Replace G with an alias to F if possible, or else a thunk to F. Deletes G.
16381638 void MergeFunctions::writeThunkOrAlias(Function *F, Function *G) {
1639 if (HasGlobalAliases && G->hasUnnamedAddr()) {
1639 if (HasGlobalAliases && G->hasGlobalUnnamedAddr()) {
16401640 if (G->hasExternalLinkage() || G->hasLocalLinkage() ||
16411641 G->hasWeakLinkage()) {
16421642 writeAlias(F, G);
831831 GlobalVariable *GV =
832832 new GlobalVariable(M, StrConst->getType(), true,
833833 GlobalValue::PrivateLinkage, StrConst, kAsanGenPrefix);
834 if (AllowMerging) GV->setUnnamedAddr(true);
834 if (AllowMerging) GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
835835 GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
836836 return GV;
837837 }
848848 auto GV = new GlobalVariable(M, LocStruct->getType(), true,
849849 GlobalValue::PrivateLinkage, LocStruct,
850850 kAsanGenPrefix);
851 GV->setUnnamedAddr(true);
851 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
852852 return GV;
853853 }
854854
136136 new GlobalVariable(M, StrConst->getType(), true,
137137 GlobalValue::PrivateLinkage, StrConst, "");
138138 if (AllowMerging)
139 GV->setUnnamedAddr(true);
139 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
140140 GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
141141 return GV;
142142 }
690690 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
691691 Function *F = Function::Create(FTy, GlobalValue::InternalLinkage,
692692 "__llvm_gcov_init", M);
693 F->setUnnamedAddr(true);
693 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
694694 F->setLinkage(GlobalValue::InternalLinkage);
695695 F->addFnAttr(Attribute::NoInline);
696696 if (Options.NoRedZone)
765765 ConstantArray::get(EdgeTableTy,
766766 makeArrayRef(&EdgeTable[0],TableSize)),
767767 "__llvm_gcda_edge_table");
768 EdgeTableGV->setUnnamedAddr(true);
768 EdgeTableGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
769769 return EdgeTableGV;
770770 }
771771
839839 ConstantInt::get(Type::getInt32Ty(*Ctx),
840840 0xffffffff),
841841 "__llvm_gcov_global_state_pred");
842 GV->setUnnamedAddr(true);
842 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
843843 }
844844 return GV;
845845 }
851851 if (!WriteoutF)
852852 WriteoutF = Function::Create(WriteoutFTy, GlobalValue::InternalLinkage,
853853 "__llvm_gcov_writeout", M);
854 WriteoutF->setUnnamedAddr(true);
854 WriteoutF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
855855 WriteoutF->addFnAttr(Attribute::NoInline);
856856 if (Options.NoRedZone)
857857 WriteoutF->addFnAttr(Attribute::NoRedZone);
911911 void GCOVProfiler::insertIndirectCounterIncrement() {
912912 Function *Fn =
913913 cast(GCOVProfiler::getIncrementIndirectCounterFunc());
914 Fn->setUnnamedAddr(true);
914 Fn->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
915915 Fn->setLinkage(GlobalValue::InternalLinkage);
916916 Fn->addFnAttr(Attribute::NoInline);
917917 if (Options.NoRedZone)
968968 "__llvm_gcov_flush", M);
969969 else
970970 FlushF->setLinkage(GlobalValue::InternalLinkage);
971 FlushF->setUnnamedAddr(true);
971 FlushF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
972972 FlushF->addFnAttr(Attribute::NoInline);
973973 if (Options.NoRedZone)
974974 FlushF->addFnAttr(Attribute::NoRedZone);
505505 auto *RegisterFTy = FunctionType::get(VoidTy, false);
506506 auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
507507 getInstrProfRegFuncsName(), M);
508 RegisterF->setUnnamedAddr(true);
508 RegisterF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
509509 if (Options.NoRedZone) RegisterF->addFnAttr(Attribute::NoRedZone);
510510
511511 auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
605605 auto *F = Function::Create(FunctionType::get(VoidTy, false),
606606 GlobalValue::InternalLinkage,
607607 getInstrProfInitFuncName(), M);
608 F->setUnnamedAddr(true);
608 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
609609 F->addFnAttr(Attribute::NoInline);
610610 if (Options.NoRedZone) F->addFnAttr(Attribute::NoRedZone);
611611
776776 GlobalVariable *GV = new GlobalVariable(*M, PatternValue->getType(), true,
777777 GlobalValue::PrivateLinkage,
778778 PatternValue, ".memset_pattern");
779 GV->setUnnamedAddr(true); // Ok to merge these.
779 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); // Ok to merge these.
780780 GV->setAlignment(16);
781781 Value *PatternPtr = ConstantExpr::getBitCast(GV, Int8PtrTy);
782782 NewCall = Builder.CreateCall(MSP, {BasePtr, PatternPtr, NumBytes});
6363 // of the module and recorded in the summary index for use when importing
6464 // from that module.
6565 auto *GVar = dyn_cast(SGV);
66 if (GVar && GVar->isConstant() && GVar->hasUnnamedAddr())
66 if (GVar && GVar->isConstant() && GVar->hasGlobalUnnamedAddr())
6767 return false;
6868
6969 if (GVar && GVar->hasSection())
104104 }
105105 }
106106
107 if (StoredVal == GV->getInitializer()) {
107 if (GV->hasInitializer() && StoredVal == GV->getInitializer()) {
108108 if (GS.StoredType < GlobalStatus::InitializerStored)
109109 GS.StoredType = GlobalStatus::InitializerStored;
110110 } else if (isa(StoredVal) &&
45394539 Array = new GlobalVariable(M, ArrayTy, /*constant=*/true,
45404540 GlobalVariable::PrivateLinkage, Initializer,
45414541 "switch.table");
4542 Array->setUnnamedAddr(true);
4542 Array->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
45434543 Kind = ArrayKind;
45444544 }
45454545
0 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
1 ; RUN: verify-uselistorder %s
2
3 ; CHECK: @c = local_unnamed_addr constant i32 0
4 @c = local_unnamed_addr constant i32 0
5
6 ; CHECK: @a = local_unnamed_addr alias i32, i32* @c
7 @a = local_unnamed_addr alias i32, i32* @c
8
9 ; CHECK: define void @f() local_unnamed_addr {
10 define void @f() local_unnamed_addr {
11 ret void
12 }
7979
8080 ;; Global Variables
8181 ; Format: [@ =] [Linkage] [Visibility] [DLLStorageClass]
82 ; [ThreadLocal] [unnamed_addr] [AddrSpace] [ExternallyInitialized]
82 ; [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [ExternallyInitialized]
8383 ; []
8484 ; [, section "name"] [, comdat [($name)]] [, align ]
8585
141141 @g.localexec = thread_local(localexec) global i32 0
142142 ; CHECK: @g.localexec = thread_local(localexec) global i32 0
143143
144 ; Global Variables -- unnamed_addr
144 ; Global Variables -- unnamed_addr and local_unnamed_addr
145145 @g.unnamed_addr = unnamed_addr global i32 0
146146 ; CHECK: @g.unnamed_addr = unnamed_addr global i32 0
147 @g.local_unnamed_addr = local_unnamed_addr global i32 0
148 ; CHECK: @g.local_unnamed_addr = local_unnamed_addr global i32 0
147149
148150 ; Global Variables -- AddrSpace
149151 @g.addrspace = addrspace(1) global i32 0
244246 @a.localexec = thread_local(localexec) alias i32, i32* @g.localexec
245247 ; CHECK: @a.localexec = thread_local(localexec) alias i32, i32* @g.localexec
246248
247 ; Aliases -- unnamed_addr
249 ; Aliases -- unnamed_addr and local_unnamed_addr
248250 @a.unnamed_addr = unnamed_addr alias i32, i32* @g.unnamed_addr
249251 ; CHECK: @a.unnamed_addr = unnamed_addr alias i32, i32* @g.unnamed_addr
252 @a.local_unnamed_addr = local_unnamed_addr alias i32, i32* @g.local_unnamed_addr
253 ; CHECK: @a.local_unnamed_addr = local_unnamed_addr alias i32, i32* @g.local_unnamed_addr
250254
251255 ;; IFunc
252256 ; Format @ = [Linkage] [Visibility] ifunc ,
277281 ; Format: define [linkage] [visibility] [DLLStorageClass]
278282 ; [cconv] [ret attrs]
279283 ; @ ([argument list])
280 ; [unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
284 ; [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"] [comdat [($name)]]
281285 ; [align N] [gc] [prefix Constant] [prologue Constant]
282286 ; [personality Constant] { ... }
283287
522526 declare void @f.param.dereferenceable_or_null(i8* dereferenceable_or_null(4))
523527 ; CHECK: declare void @f.param.dereferenceable_or_null(i8* dereferenceable_or_null(4))
524528
525 ; Functions -- unnamed_addr
529 ; Functions -- unnamed_addr and local_unnamed_addr
526530 declare void @f.unnamed_addr() unnamed_addr
527531 ; CHECK: declare void @f.unnamed_addr() unnamed_addr
532 declare void @f.local_unnamed_addr() local_unnamed_addr
533 ; CHECK: declare void @f.local_unnamed_addr() local_unnamed_addr
528534
529535 ; Functions -- fn Attrs (Function attributes)
530536 declare void @f.alignstack4() alignstack(4)
22 ; RUN: llc -mtriple=powerpc-apple-darwin9 -O0 < %s | FileCheck --check-prefix=CHECK-D89 %s
33 ; RUN: llc -mtriple=powerpc-apple-darwin8 -O0 < %s | FileCheck --check-prefix=CHECK-D89 %s
44
5 @v1 = linkonce_odr constant i32 32
5 @v1 = linkonce_odr local_unnamed_addr constant i32 32
66 ; CHECK: .globl _v1
77 ; CHECK: .weak_def_can_be_hidden _v1
88
2525 ret i32* @v2
2626 }
2727
28 @v3 = linkonce_odr unnamed_addr global i32 32
28 @v3 = linkonce_odr unnamed_addr constant i32 32
2929 ; CHECK: .globl _v3
3030 ; CHECK: .weak_def_can_be_hidden _v3
3131
3636 ret i32* @v3
3737 }
3838
39 @v4 = linkonce_odr global i32 32
39 @v4 = linkonce_odr unnamed_addr global i32 32
4040 ; CHECK: .globl _v4
41 ; CHECK: .weak_definition _v4
41 ; CHECK: .weak_def_can_be_hidden _v4
4242
4343 ; CHECK-D89: .globl _v4
4444 ; CHECK-D89: .weak_definition _v4
33 ; RUN: llc -mtriple=i686-apple-darwin9 -O0 < %s | FileCheck --check-prefix=CHECK-D89 %s
44 ; RUN: llc -mtriple=i686-apple-darwin8 -O0 < %s | FileCheck --check-prefix=CHECK-D89 %s
55
6 @v1 = linkonce_odr constant i32 32
6 @v1 = linkonce_odr local_unnamed_addr constant i32 32
77 ; CHECK: .globl _v1
88 ; CHECK: .weak_def_can_be_hidden _v1
99
2626 ret i32* @v2
2727 }
2828
29 @v3 = linkonce_odr unnamed_addr global i32 32
29 @v3 = linkonce_odr unnamed_addr constant i32 32
3030 ; CHECK: .globl _v3
3131 ; CHECK: .weak_def_can_be_hidden _v3
3232
3737 ret i32* @v3
3838 }
3939
40 @v4 = linkonce_odr global i32 32
40 @v4 = linkonce_odr unnamed_addr global i32 32
4141 ; CHECK: .globl _v4
42 ; CHECK: .weak_definition _v4
42 ; CHECK: .weak_def_can_be_hidden _v4
4343
4444 ; CHECK-D89: .globl _v4
4545 ; CHECK-D89: .weak_definition _v4
99
1010 declare void @foo() readnone
1111
12 ; CHECK-LABEL: define i8* @test(i8* %p) {
12 ; CHECK-LABEL: define i8* @test(i8* %p)
1313 ; CHECK: %a = alloca i8*, align 8
1414 ; CHECK: store i8* %p, i8** %a, align 8
1515 ; CHECK: call void @foo() [ "abc"(i8** %a) ]
3232 ret i32* @zed1
3333 }
3434
35 ; ZED1_AND_ZED2: d zed2
36 @zed2 = linkonce_odr unnamed_addr global i32 42
35 ; ZED1_AND_ZED2: r zed2
36 @zed2 = linkonce_odr unnamed_addr constant i32 42
3737
3838 define i32 @useZed2() {
3939 %x = load i32, i32* @zed2
0 ; RUN: llvm-as < %s >%t1
11 ; RUN: llvm-lto -o %t2 -dso-symbol=foo1 -dso-symbol=foo2 -dso-symbol=foo3 \
2 ; RUN: -dso-symbol=foo4 -dso-symbol=v1 -dso-symbol=v2 %t1 -O0
2 ; RUN: -dso-symbol=v1 -dso-symbol=v2 -dso-symbol=v3 \
3 ; RUN: -dso-symbol=v4 -dso-symbol=v5 -dso-symbol=v6 %t1 -O0
34 ; RUN: llvm-nm %t2 | FileCheck %s
45
56 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
67 target triple = "x86_64-unknown-linux-gnu"
78
8 ; CHECK: t foo1
9 ; CHECK: W foo1
910 define linkonce_odr void @foo1() noinline {
1011 ret void
1112 }
1213
13 ; CHECK: W foo2
14 define linkonce_odr void @foo2() noinline {
14 ; CHECK: t foo2
15 define linkonce_odr void @foo2() local_unnamed_addr noinline {
1516 ret void
1617 }
1718
1819 ; CHECK: t foo3
19 define linkonce_odr void @foo3() noinline {
20 define linkonce_odr void @foo3() unnamed_addr noinline {
2021 ret void
2122 }
2223
23 ; CHECK: W foo4
24 define linkonce_odr void @foo4() noinline {
24 ; CHECK: V v1
25 @v1 = linkonce_odr constant i32 32
26
27 ; CHECK: r v2
28 @v2 = linkonce_odr local_unnamed_addr constant i32 32
29
30 ; CHECK: r v3
31 @v3 = linkonce_odr unnamed_addr constant i32 32
32
33 ; CHECK: V v4
34 @v4 = linkonce_odr global i32 32
35
36 ; CHECK: V v5
37 @v5 = linkonce_odr local_unnamed_addr global i32 32
38
39 ; CHECK: d v6
40 @v6 = linkonce_odr unnamed_addr global i32 32
41
42 define void @use() {
43 call void @foo1()
44 call void @foo2()
45 call void @foo3()
46 %x1 = load i32, i32* @v1
47 %x2 = load i32, i32* @v2
48 %x3 = load i32, i32* @v3
49 %x4 = load i32, i32* @v4
50 %x5 = load i32, i32* @v5
51 %x6 = load i32, i32* @v6
2552 ret void
2653 }
27
28 ; CHECK: r v1
29 @v1 = linkonce_odr constant i32 32
30
31 define i32 @useV1() {
32 %x = load i32, i32* @v1
33 ret i32 %x
34 }
35
36 ; CHECK: V v2
37 @v2 = linkonce_odr global i32 32
38
39 define i32 @useV2() {
40 %x = load i32, i32* @v2
41 ret i32 %x
42 }
43
44 declare void @f(void()*)
45
46 declare void @p()
47
48 define void @bar() personality void()* @p {
49 bb0:
50 call void @foo1()
51 call void @f(void()* @foo2)
52 invoke void @foo3() to label %bb1 unwind label %clean
53 bb1:
54 invoke void @f(void()* @foo4) to label %bb2 unwind label %clean
55 bb2:
56 ret void
57 clean:
58 landingpad {i32, i32} cleanup
59 ret void
60 }
2323 ; PLAIN: @F1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2)
2424 ; PLAIN: @H8 = global i8* getelementptr (i8, i8* null, i32 -1)
2525 ; PLAIN: @H1 = global i1* getelementptr (i1, i1* null, i32 -1)
26 ; OPT: @G8 = global i8* null
27 ; OPT: @G1 = global i1* null
28 ; OPT: @F8 = global i8* inttoptr (i64 -1 to i8*)
29 ; OPT: @F1 = global i1* inttoptr (i64 -1 to i1*)
30 ; OPT: @H8 = global i8* inttoptr (i64 -1 to i8*)
31 ; OPT: @H1 = global i1* inttoptr (i64 -1 to i1*)
32 ; TO: @G8 = global i8* null
33 ; TO: @G1 = global i1* null
34 ; TO: @F8 = global i8* inttoptr (i64 -1 to i8*)
35 ; TO: @F1 = global i1* inttoptr (i64 -1 to i1*)
36 ; TO: @H8 = global i8* inttoptr (i64 -1 to i8*)
37 ; TO: @H1 = global i1* inttoptr (i64 -1 to i1*)
26 ; OPT: @G8 = local_unnamed_addr global i8* null
27 ; OPT: @G1 = local_unnamed_addr global i1* null
28 ; OPT: @F8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
29 ; OPT: @F1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
30 ; OPT: @H8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
31 ; OPT: @H1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
32 ; TO: @G8 = local_unnamed_addr global i8* null
33 ; TO: @G1 = local_unnamed_addr global i1* null
34 ; TO: @F8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
35 ; TO: @F1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
36 ; TO: @H8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
37 ; TO: @H1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
3838
3939 @G8 = global i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1)
4040 @G1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1)
5656 ; PLAIN: @g = constant i64 ptrtoint (double* getelementptr ({ i1, double }, { i1, double }* null, i64 0, i32 1) to i64)
5757 ; PLAIN: @h = constant i64 ptrtoint (i1** getelementptr (i1*, i1** null, i32 1) to i64)
5858 ; PLAIN: @i = constant i64 ptrtoint (i1** getelementptr ({ i1, i1* }, { i1, i1* }* null, i64 0, i32 1) to i64)
59 ; OPT: @a = constant i64 18480
60 ; OPT: @b = constant i64 8
61 ; OPT: @c = constant i64 16
62 ; OPT: @d = constant i64 88
63 ; OPT: @e = constant i64 16
64 ; OPT: @f = constant i64 1
65 ; OPT: @g = constant i64 8
66 ; OPT: @h = constant i64 8
67 ; OPT: @i = constant i64 8
68 ; TO: @a = constant i64 18480
69 ; TO: @b = constant i64 8
70 ; TO: @c = constant i64 16
71 ; TO: @d = constant i64 88
72 ; TO: @e = constant i64 16
73 ; TO: @f = constant i64 1
74 ; TO: @g = constant i64 8
75 ; TO: @h = constant i64 8
76 ; TO: @i = constant i64 8
59 ; OPT: @a = local_unnamed_addr constant i64 18480
60 ; OPT: @b = local_unnamed_addr constant i64 8
61 ; OPT: @c = local_unnamed_addr constant i64 16
62 ; OPT: @d = local_unnamed_addr constant i64 88
63 ; OPT: @e = local_unnamed_addr constant i64 16
64 ; OPT: @f = local_unnamed_addr constant i64 1
65 ; OPT: @g = local_unnamed_addr constant i64 8
66 ; OPT: @h = local_unnamed_addr constant i64 8
67 ; OPT: @i = local_unnamed_addr constant i64 8
68 ; TO: @a = local_unnamed_addr constant i64 18480
69 ; TO: @b = local_unnamed_addr constant i64 8
70 ; TO: @c = local_unnamed_addr constant i64 16
71 ; TO: @d = local_unnamed_addr constant i64 88
72 ; TO: @e = local_unnamed_addr constant i64 16
73 ; TO: @f = local_unnamed_addr constant i64 1
74 ; TO: @g = local_unnamed_addr constant i64 8
75 ; TO: @h = local_unnamed_addr constant i64 8
76 ; TO: @i = local_unnamed_addr constant i64 8
7777
7878 @a = constant i64 mul (i64 3, i64 mul (i64 ptrtoint ({[7 x double], [7 x double]}* getelementptr ({[7 x double], [7 x double]}, {[7 x double], [7 x double]}* null, i64 11) to i64), i64 5))
7979 @b = constant i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}, {i1, [13 x double]}* null, i64 0, i32 1) to i64)
9090 ; PLAIN: @M = constant i64* getelementptr (i64, i64* null, i32 1)
9191 ; PLAIN: @N = constant i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1)
9292 ; PLAIN: @O = constant i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1)
93 ; OPT: @M = constant i64* inttoptr (i64 8 to i64*)
94 ; OPT: @N = constant i64* inttoptr (i64 8 to i64*)
95 ; OPT: @O = constant i64* inttoptr (i64 8 to i64*)
96 ; TO: @M = constant i64* inttoptr (i64 8 to i64*)
97 ; TO: @N = constant i64* inttoptr (i64 8 to i64*)
98 ; TO: @O = constant i64* inttoptr (i64 8 to i64*)
93 ; OPT: @M = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
94 ; OPT: @N = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
95 ; OPT: @O = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
96 ; TO: @M = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
97 ; TO: @N = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
98 ; TO: @O = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
9999
100100 @M = constant i64* getelementptr (i64, i64* null, i32 1)
101101 @N = constant i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1)
105105
106106 ; PLAIN: @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
107107 ; PLAIN: @Z = global i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
108 ; OPT: @Y = global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
109 ; OPT: @Z = global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
110 ; TO: @Y = global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
111 ; TO: @Z = global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
108 ; OPT: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
109 ; OPT: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
110 ; TO: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
111 ; TO: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
112112
113113 @ext = external global [3 x { i32, i32 }]
114114 @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 1), i64 1)
141141 ; PLAIN: %t = bitcast i1* getelementptr (i1, i1* null, i32 -1) to i1*
142142 ; PLAIN: ret i1* %t
143143 ; PLAIN: }
144 ; OPT: define i8* @goo8() #0 {
144 ; OPT: define i8* @goo8() local_unnamed_addr #0 {
145145 ; OPT: ret i8* null
146146 ; OPT: }
147 ; OPT: define i1* @goo1() #0 {
147 ; OPT: define i1* @goo1() local_unnamed_addr #0 {
148148 ; OPT: ret i1* null
149149 ; OPT: }
150 ; OPT: define i8* @foo8() #0 {
150 ; OPT: define i8* @foo8() local_unnamed_addr #0 {
151151 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
152152 ; OPT: }
153 ; OPT: define i1* @foo1() #0 {
153 ; OPT: define i1* @foo1() local_unnamed_addr #0 {
154154 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
155155 ; OPT: }
156 ; OPT: define i8* @hoo8() #0 {
156 ; OPT: define i8* @hoo8() local_unnamed_addr #0 {
157157 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
158158 ; OPT: }
159 ; OPT: define i1* @hoo1() #0 {
159 ; OPT: define i1* @hoo1() local_unnamed_addr #0 {
160160 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
161161 ; OPT: }
162 ; TO: define i8* @goo8() #0 {
162 ; TO: define i8* @goo8() local_unnamed_addr #0 {
163163 ; TO: ret i8* null
164164 ; TO: }
165 ; TO: define i1* @goo1() #0 {
165 ; TO: define i1* @goo1() local_unnamed_addr #0 {
166166 ; TO: ret i1* null
167167 ; TO: }
168 ; TO: define i8* @foo8() #0 {
168 ; TO: define i8* @foo8() local_unnamed_addr #0 {
169169 ; TO: ret i8* inttoptr (i64 -1 to i8*)
170170 ; TO: }
171 ; TO: define i1* @foo1() #0 {
171 ; TO: define i1* @foo1() local_unnamed_addr #0 {
172172 ; TO: ret i1* inttoptr (i64 -1 to i1*)
173173 ; TO: }
174 ; TO: define i8* @hoo8() #0 {
174 ; TO: define i8* @hoo8() local_unnamed_addr #0 {
175175 ; TO: ret i8* inttoptr (i64 -1 to i8*)
176176 ; TO: }
177 ; TO: define i1* @hoo1() #0 {
177 ; TO: define i1* @hoo1() local_unnamed_addr #0 {
178178 ; TO: ret i1* inttoptr (i64 -1 to i1*)
179179 ; TO: }
180180 ; SCEV: Classifying expressions for: @goo8
255255 ; PLAIN: %t = bitcast i64 ptrtoint (i1** getelementptr ({ i1, i1* }, { i1, i1* }* null, i64 0, i32 1) to i64) to i64
256256 ; PLAIN: ret i64 %t
257257 ; PLAIN: }
258 ; OPT: define i64 @fa() #0 {
258 ; OPT: define i64 @fa() local_unnamed_addr #0 {
259259 ; OPT: ret i64 18480
260260 ; OPT: }
261 ; OPT: define i64 @fb() #0 {
261 ; OPT: define i64 @fb() local_unnamed_addr #0 {
262262 ; OPT: ret i64 8
263263 ; OPT: }
264 ; OPT: define i64 @fc() #0 {
264 ; OPT: define i64 @fc() local_unnamed_addr #0 {
265265 ; OPT: ret i64 16
266266 ; OPT: }
267 ; OPT: define i64 @fd() #0 {
267 ; OPT: define i64 @fd() local_unnamed_addr #0 {
268268 ; OPT: ret i64 88
269269 ; OPT: }
270 ; OPT: define i64 @fe() #0 {
270 ; OPT: define i64 @fe() local_unnamed_addr #0 {
271271 ; OPT: ret i64 16
272272 ; OPT: }
273 ; OPT: define i64 @ff() #0 {
273 ; OPT: define i64 @ff() local_unnamed_addr #0 {
274274 ; OPT: ret i64 1
275275 ; OPT: }
276 ; OPT: define i64 @fg() #0 {
276 ; OPT: define i64 @fg() local_unnamed_addr #0 {
277277 ; OPT: ret i64 8
278278 ; OPT: }
279 ; OPT: define i64 @fh() #0 {
279 ; OPT: define i64 @fh() local_unnamed_addr #0 {
280280 ; OPT: ret i64 8
281281 ; OPT: }
282 ; OPT: define i64 @fi() #0 {
282 ; OPT: define i64 @fi() local_unnamed_addr #0 {
283283 ; OPT: ret i64 8
284284 ; OPT: }
285 ; TO: define i64 @fa() #0 {
285 ; TO: define i64 @fa() local_unnamed_addr #0 {
286286 ; TO: ret i64 18480
287287 ; TO: }
288 ; TO: define i64 @fb() #0 {
288 ; TO: define i64 @fb() local_unnamed_addr #0 {
289289 ; TO: ret i64 8
290290 ; TO: }
291 ; TO: define i64 @fc() #0 {
291 ; TO: define i64 @fc() local_unnamed_addr #0 {
292292 ; TO: ret i64 16
293293 ; TO: }
294 ; TO: define i64 @fd() #0 {
294 ; TO: define i64 @fd() local_unnamed_addr #0 {
295295 ; TO: ret i64 88
296296 ; TO: }
297 ; TO: define i64 @fe() #0 {
297 ; TO: define i64 @fe() local_unnamed_addr #0 {
298298 ; TO: ret i64 16
299299 ; TO: }
300 ; TO: define i64 @ff() #0 {
300 ; TO: define i64 @ff() local_unnamed_addr #0 {
301301 ; TO: ret i64 1
302302 ; TO: }
303 ; TO: define i64 @fg() #0 {
303 ; TO: define i64 @fg() local_unnamed_addr #0 {
304304 ; TO: ret i64 8
305305 ; TO: }
306 ; TO: define i64 @fh() #0 {
306 ; TO: define i64 @fh() local_unnamed_addr #0 {
307307 ; TO: ret i64 8
308308 ; TO: }
309 ; TO: define i64 @fi() #0 {
309 ; TO: define i64 @fi() local_unnamed_addr #0 {
310310 ; TO: ret i64 8
311311 ; TO: }
312312 ; SCEV: Classifying expressions for: @fa
386386 ; PLAIN: %t = bitcast i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1) to i64*
387387 ; PLAIN: ret i64* %t
388388 ; PLAIN: }
389 ; OPT: define i64* @fM() #0 {
389 ; OPT: define i64* @fM() local_unnamed_addr #0 {
390390 ; OPT: ret i64* inttoptr (i64 8 to i64*)
391391 ; OPT: }
392 ; OPT: define i64* @fN() #0 {
392 ; OPT: define i64* @fN() local_unnamed_addr #0 {
393393 ; OPT: ret i64* inttoptr (i64 8 to i64*)
394394 ; OPT: }
395 ; OPT: define i64* @fO() #0 {
395 ; OPT: define i64* @fO() local_unnamed_addr #0 {
396396 ; OPT: ret i64* inttoptr (i64 8 to i64*)
397397 ; OPT: }
398 ; TO: define i64* @fM() #0 {
398 ; TO: define i64* @fM() local_unnamed_addr #0 {
399399 ; TO: ret i64* inttoptr (i64 8 to i64*)
400400 ; TO: }
401 ; TO: define i64* @fN() #0 {
401 ; TO: define i64* @fN() local_unnamed_addr #0 {
402402 ; TO: ret i64* inttoptr (i64 8 to i64*)
403403 ; TO: }
404 ; TO: define i64* @fO() #0 {
404 ; TO: define i64* @fO() local_unnamed_addr #0 {
405405 ; TO: ret i64* inttoptr (i64 8 to i64*)
406406 ; TO: }
407407 ; SCEV: Classifying expressions for: @fM
431431 ; PLAIN: %t = bitcast i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
432432 ; PLAIN: ret i32* %t
433433 ; PLAIN: }
434 ; OPT: define i32* @fZ() #0 {
434 ; OPT: define i32* @fZ() local_unnamed_addr #0 {
435435 ; OPT: ret i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
436436 ; OPT: }
437 ; TO: define i32* @fZ() #0 {
437 ; TO: define i32* @fZ() local_unnamed_addr #0 {
438438 ; TO: ret i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
439439 ; TO: }
440440 ; SCEV: Classifying expressions for: @fZ
11
22 ; PR8389: Globals with weak_odr linkage type must not be modified
33
4 ; CHECK: weak_odr global i32 0
4 ; CHECK: weak_odr local_unnamed_addr global i32 0
55
66 @SomeVar = weak_odr global i32 0
77
1515 ; CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* @ia to i8*)], section "llvm.metadata"
1616
1717 @sameAsUsed = global [1 x i8*] [i8* addrspacecast(i8 addrspace(1)* @ca to i8*)]
18 ; CHECK-DAG: @sameAsUsed = global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* @c to i8*)]
18 ; CHECK-DAG: @sameAsUsed = local_unnamed_addr global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* @c to i8*)]
1919
2020 @ca = internal alias i8, i8 addrspace(1)* @c
2121 ; CHECK: @ca = internal alias i8, i8 addrspace(1)* @c
1212 ; CHECK-DAG: @llvm.compiler.used = appending global [2 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* @ia], section "llvm.metadata"
1313
1414 @sameAsUsed = global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca]
15 ; CHECK-DAG: @sameAsUsed = global [3 x i8*] [i8* bitcast (void ()* @f to i8*), i8* bitcast (void ()* @f to i8*), i8* @c]
15 ; CHECK-DAG: @sameAsUsed = local_unnamed_addr global [3 x i8*] [i8* bitcast (void ()* @f to i8*), i8* bitcast (void ()* @f to i8*), i8* @c]
1616
1717 @other = global i32* bitcast (void ()* @fa to i32*)
18 ; CHECK-DAG: @other = global i32* bitcast (void ()* @f to i32*)
18 ; CHECK-DAG: @other = local_unnamed_addr global i32* bitcast (void ()* @f to i32*)
1919
2020 @fa = internal alias void (), void ()* @f
2121 ; CHECK: @fa = internal alias void (), void ()* @f
0 ; RUN: opt -S -globalopt < %s | FileCheck %s
11
2 ; CHECK: @tmp = global i32 42
2 ; CHECK: @tmp = local_unnamed_addr global i32 42
33
44 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
55 @tmp = global i32 0
33
44 @.str91250 = global [3 x i8] zeroinitializer
55
6 ; CHECK: @A = global i1 false
6 ; CHECK: @A = local_unnamed_addr global i1 false
77 @A = global i1 icmp ne (i64 sub nsw (i64 ptrtoint (i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str91250, i64 0, i64 1) to i64), i64 ptrtoint ([3 x i8]* @.str91250 to i64)), i64 1)
88
99 ; PR11352
1010
1111 @xs = global [2 x i32] zeroinitializer, align 4
12 ; CHECK: @xs = global [2 x i32] [i32 1, i32 1]
12 ; CHECK: @xs = local_unnamed_addr global [2 x i32] [i32 1, i32 1]
1313
1414 ; PR12642
1515 %PR12642.struct = type { i8 }
3131 @f = internal global %closure zeroinitializer, align 4
3232 @m = global i32 0, align 4
3333 ; CHECK-NOT: @f
34 ; CHECK: @m = global i32 13
34 ; CHECK: @m = local_unnamed_addr global i32 13
3535
3636 define internal i32 @test2_helper(%closure* %this, i32 %b) {
3737 entry:
5252 ; PR19955
5353
5454 @dllimportptr = global i32* null, align 4
55 ; CHECK: @dllimportptr = global i32* null, align 4
55 ; CHECK: @dllimportptr = local_unnamed_addr global i32* null, align 4
5656 @dllimportvar = external dllimport global i32
5757 define internal void @test3() {
5858 entry:
6161 }
6262
6363 @dllexportptr = global i32* null, align 4
64 ; CHECK: @dllexportptr = global i32* @dllexportvar, align 4
64 ; CHECK: @dllexportptr = local_unnamed_addr global i32* @dllexportvar, align 4
6565 @dllexportvar = dllexport global i32 0, align 4
6666 ; CHECK: @dllexportvar = dllexport global i32 20, align 4
6767 define internal void @test4() {
8282
8383 @test6_v1 = internal global { i32, i32 } { i32 42, i32 0 }, align 8
8484 @test6_v2 = global i32 0, align 4
85 ; CHECK: @test6_v2 = global i32 42, align 4
85 ; CHECK: @test6_v2 = local_unnamed_addr global i32 42, align 4
8686 define internal void @test6() {
8787 %load = load { i32, i32 }, { i32, i32 }* @test6_v1, align 8
8888 %xv0 = extractvalue { i32, i32 } %load, 0
22 ; Don't get fooled by the inbounds keyword; it doesn't change
33 ; the computed address.
44
5 ; CHECK: @H = global i32 2
6 ; CHECK: @I = global i32 2
5 ; CHECK: @H = local_unnamed_addr global i32 2
6 ; CHECK: @I = local_unnamed_addr global i32 2
77
88 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR } ]
99 @addr = external global i32
11
22 ; This test is hint, what could globalOpt optimize and what it can't
33 ; FIXME: @tmp and @tmp2 can be safely set to 42
4 ; CHECK: @tmp = global i32 0
5 ; CHECK: @tmp2 = global i32 0
4 ; CHECK: @tmp = local_unnamed_addr global i32 0
5 ; CHECK: @tmp2 = local_unnamed_addr global i32 0
66 ; CHECK: @tmp3 = global i32 0
77
88 @tmp = global i32 0
11 ; rdar://11022897
22
33 ; Globalopt should be able to evaluate an invoke.
4 ; CHECK: @tmp = global i32 1
4 ; CHECK: @tmp = local_unnamed_addr global i32 1
55
66 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
77 @tmp = global i32 0
55 define linkonce_odr void @foo() comdat($c) {
66 ret void
77 }
8 ; CHECK: define linkonce_odr void @foo() comdat($c)
8 ; CHECK: define linkonce_odr void @foo() local_unnamed_addr comdat($c)
99
1010 define linkonce_odr void @bar() comdat($c) {
1111 ret void
1212 }
13 ; CHECK: define linkonce_odr void @bar() comdat($c)
13 ; CHECK: define linkonce_odr void @bar() local_unnamed_addr comdat($c)
1414
1515 define void @zed() {
1616 call void @foo()
99 ; CHECK: @b = internal global i32 0, align 4
1010 ; CHECK: @c = internal unnamed_addr global i32 0, align 4
1111 ; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
12 ; CHECK: @e = linkonce_odr global i32 0
12 ; CHECK: @e = linkonce_odr local_unnamed_addr global i32 0
1313
1414 ; CHECK: define internal fastcc void @used_internal() unnamed_addr {
1515 define internal void @used_internal() {
1515 ret void
1616 }
1717
18 ; CHECK: define internal void @h() {
19 define linkonce_odr void @h() {
18 ; CHECK: define internal void @h() local_unnamed_addr {
19 define linkonce_odr void @h() local_unnamed_addr {
2020 ret void
2121 }
2323 ; NM: T f3
2424
2525 target triple = "x86_64-unknown-linux-gnu"
26
27 ; CHECK-DAG: @g1 = linkonce_odr constant i32 32
28 @g1 = linkonce_odr constant i32 32
29
30 ; CHECK-DAG: @g2 = internal local_unnamed_addr constant i32 32
31 @g2 = linkonce_odr local_unnamed_addr constant i32 32
32
33 ; CHECK-DAG: @g3 = internal unnamed_addr constant i32 32
34 @g3 = linkonce_odr unnamed_addr constant i32 32
35
36 ; CHECK-DAG: @g4 = linkonce_odr global i32 32
37 @g4 = linkonce_odr global i32 32
38
39 ; CHECK-DAG: @g5 = linkonce_odr local_unnamed_addr global i32 32
40 @g5 = linkonce_odr local_unnamed_addr global i32 32
41
42 ; CHECK-DAG: @g6 = internal unnamed_addr global i32 32
43 @g6 = linkonce_odr unnamed_addr global i32 32
2644
2745 @g7 = extern_weak global i32
2846 ; CHECK-DAG: @g7 = extern_weak global i32
5270
5371 ; CHECK-DAG: define internal void @f4()
5472 ; OPT2-NOT: @f4
55 define linkonce_odr void @f4() {
73 define linkonce_odr void @f4() local_unnamed_addr {
5674 ret void
5775 }
5876
6179 define linkonce_odr void @f5() {
6280 ret void
6381 }
64 @g5 = global void()* @f5
82 @g9 = global void()* @f5
6583
6684 ; CHECK-DAG: define internal void @f6() unnamed_addr
6785 ; OPT-DAG: define internal void @f6() unnamed_addr
6886 define linkonce_odr void @f6() unnamed_addr {
6987 ret void
7088 }
71 @g6 = global void()* @f6
89 @g10 = global void()* @f6
7290
7391 define i32* @f7() {
7492 ret i32* @g7
88106 ; API: f8 PREVAILING_DEF_IRONLY_EXP
89107 ; API: g7 UNDEF
90108 ; API: g8 UNDEF
91 ; API: g5 PREVAILING_DEF_IRONLY_EXP
92 ; API: g6 PREVAILING_DEF_IRONLY_EXP
109 ; API: g9 PREVAILING_DEF_IRONLY_EXP
110 ; API: g10 PREVAILING_DEF_IRONLY_EXP
108108 uint64_t CommonSize = 0;
109109 unsigned CommonAlign = 0;
110110 bool IsLinkonceOdr = true;
111 bool UnnamedAddr = true;
111 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::Global;
112112 GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
113113 bool CommonInternal = false;
114114 bool UseCommon = false;
550550
551551 sym.visibility = LDPV_DEFAULT;
552552 if (GV) {
553 Res.UnnamedAddr &= GV->hasUnnamedAddr();
553 Res.UnnamedAddr =
554 GlobalValue::getMinUnnamedAddr(Res.UnnamedAddr, GV->getUnnamedAddr());
554555 Res.IsLinkonceOdr &= GV->hasLinkOnceLinkage();
555556 Res.Visibility = getMinVisibility(Res.Visibility, GV->getVisibility());
556557 switch (GV->getVisibility()) {
689690 return Obj.takeIndex();
690691 }
691692
692 static std::unique_ptr getModuleForFile(
693 LLVMContext &Context, claimed_file &F, const void *View, StringRef Name,
694 raw_fd_ostream *ApiFile, StringSet<> &Internalize, StringSet<> &Maybe,
695 std::vector &Keep, StringMap &Realign) {
693 static std::unique_ptr
694 getModuleForFile(LLVMContext &Context, claimed_file &F, const void *View,
695 StringRef Name, raw_fd_ostream *ApiFile,
696 StringSet<> &Internalize, std::vector &Keep,
697 StringMap &Realign) {
696698 MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize), Name);
697699 ErrorOr> ObjOrErr =
698700 object::IRObjectFile::create(BufferRef, Context);
826828 break;
827829
828830 case LDPR_PREVAILING_DEF_IRONLY_EXP: {
829 // We can only check for address uses after we merge the modules. The
830 // reason is that this GV might have a copy in another module
831 // and in that module the address might be significant, but that
832 // copy will be LDPR_PREEMPTED_IR.
833 Maybe.insert(GV->getName());
834831 Keep.push_back(GV);
832 if (canBeOmittedFromSymbolTable(GV))
833 Internalize.insert(GV->getName());
835834 break;
836835 }
837836 }
11481147 static void linkInModule(LLVMContext &Context, IRMover &L, claimed_file &F,
11491148 const void *View, StringRef Name,
11501149 raw_fd_ostream *ApiFile, StringSet<> &Internalize,
1151 StringSet<> &Maybe, bool SetName = false) {
1150 bool SetName = false) {
11521151 std::vector Keep;
11531152 StringMap Realign;
1154 std::unique_ptr M = getModuleForFile(
1155 Context, F, View, Name, ApiFile, Internalize, Maybe, Keep, Realign);
1153 std::unique_ptr M = getModuleForFile(Context, F, View, Name, ApiFile,
1154 Internalize, Keep, Realign);
11561155 if (!M.get())
11571156 return;
11581157 if (!options::triple.empty())
12031202 IRMover L(*NewModule.get());
12041203
12051204 StringSet<> Dummy;
1206 linkInModule(Context, L, F, View, Name, ApiFile, Dummy, Dummy, true);
1205 linkInModule(Context, L, F, View, Name, ApiFile, Dummy, true);
12071206 if (renameModuleForThinLTO(*NewModule, CombinedIndex))
12081207 message(LDPL_FATAL, "Failed to rename module for ThinLTO");
12091208
14731472 IRMover L(*Combined);
14741473
14751474 StringSet<> Internalize;
1476 StringSet<> Maybe;
14771475 for (claimed_file &F : Modules) {
14781476 // RAII object to manage the file opening and releasing interfaces with
14791477 // gold.
14811479 const void *View = getSymbolsAndView(F);
14821480 if (!View)
14831481 continue;
1484 linkInModule(Context, L, F, View, F.name, ApiFile, Internalize, Maybe);
1482 linkInModule(Context, L, F, View, F.name, ApiFile, Internalize);
14851483 }
14861484
14871485 for (const auto &Name : Internalize) {
14881486 GlobalValue *GV = Combined->getNamedValue(Name.first());
14891487 if (GV)
1490 internalize(*GV);
1491 }
1492
1493 for (const auto &Name : Maybe) {
1494 GlobalValue *GV = Combined->getNamedValue(Name.first());
1495 if (!GV)
1496 continue;
1497 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1498 if (canBeOmittedFromSymbolTable(GV))
14991488 internalize(*GV);
15001489 }
15011490