本文整理汇总了C++中GlobalValue::setUnnamedAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue::setUnnamedAddr方法的具体用法?C++ GlobalValue::setUnnamedAddr怎么用?C++ GlobalValue::setUnnamedAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalValue
的用法示例。
在下文中一共展示了GlobalValue::setUnnamedAddr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: raiseVisibilityOnValue
static void raiseVisibilityOnValue(GlobalValue &V, GlobalRenamer &R) {
if (V.hasLocalLinkage()) {
if (R.needsRenaming(V))
V.setName(R.getRename(V));
V.setLinkage(GlobalValue::ExternalLinkage);
V.setVisibility(GlobalValue::HiddenVisibility);
}
V.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
assert(!R.needsRenaming(V) && "Invalid global name.");
}
示例2: linkIfNeeded
bool ModuleLinker::linkIfNeeded(GlobalValue &GV) {
GlobalValue *DGV = getLinkedToGlobal(&GV);
if (shouldLinkOnlyNeeded() && !(DGV && DGV->isDeclaration()))
return false;
if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
auto *DGVar = dyn_cast<GlobalVariable>(DGV);
auto *SGVar = dyn_cast<GlobalVariable>(&GV);
if (DGVar && SGVar) {
if (DGVar->isDeclaration() && SGVar->isDeclaration() &&
(!DGVar->isConstant() || !SGVar->isConstant())) {
DGVar->setConstant(false);
SGVar->setConstant(false);
}
if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
unsigned Align = std::max(DGVar->getAlignment(), SGVar->getAlignment());
SGVar->setAlignment(Align);
DGVar->setAlignment(Align);
}
}
GlobalValue::VisibilityTypes Visibility =
getMinVisibility(DGV->getVisibility(), GV.getVisibility());
DGV->setVisibility(Visibility);
GV.setVisibility(Visibility);
bool HasUnnamedAddr = GV.hasUnnamedAddr() && DGV->hasUnnamedAddr();
DGV->setUnnamedAddr(HasUnnamedAddr);
GV.setUnnamedAddr(HasUnnamedAddr);
}
// Don't want to append to global_ctors list, for example, when we
// are importing for ThinLTO, otherwise the global ctors and dtors
// get executed multiple times for local variables (the latter causing
// double frees).
if (GV.hasAppendingLinkage() && isPerformingImport())
return false;
if (isPerformingImport()) {
if (!doImportAsDefinition(&GV))
return false;
} else if (!DGV && !shouldOverrideFromSrc() &&
(GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
GV.hasAvailableExternallyLinkage()))
return false;
if (GV.isDeclaration())
return false;
if (const Comdat *SC = GV.getComdat()) {
bool LinkFromSrc;
Comdat::SelectionKind SK;
std::tie(SK, LinkFromSrc) = ComdatsChosen[SC];
if (!LinkFromSrc)
return false;
}
bool LinkFromSrc = true;
if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, GV))
return true;
if (LinkFromSrc)
ValuesToLink.insert(&GV);
return false;
}
示例3: BufferRef
static std::unique_ptr<Module>
getModuleForFile(LLVMContext &Context, claimed_file &F, const void *View,
ld_plugin_input_file &Info, raw_fd_ostream *ApiFile,
StringSet<> &Internalize, StringSet<> &Maybe,
std::vector<GlobalValue *> &Keep,
StringMap<unsigned> &Realign) {
MemoryBufferRef BufferRef(StringRef((const char *)View, Info.filesize),
Info.name);
ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
object::IRObjectFile::create(BufferRef, Context);
if (std::error_code EC = ObjOrErr.getError())
message(LDPL_FATAL, "Could not read bitcode from file : %s",
EC.message().c_str());
object::IRObjectFile &Obj = **ObjOrErr;
Module &M = Obj.getModule();
M.materializeMetadata();
UpgradeDebugInfo(M);
SmallPtrSet<GlobalValue *, 8> Used;
collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
unsigned SymNum = 0;
for (auto &ObjSym : Obj.symbols()) {
GlobalValue *GV = Obj.getSymbolGV(ObjSym.getRawDataRefImpl());
if (GV && GV->hasAppendingLinkage())
Keep.push_back(GV);
if (shouldSkip(ObjSym.getFlags()))
continue;
ld_plugin_symbol &Sym = F.syms[SymNum];
++SymNum;
ld_plugin_symbol_resolution Resolution =
(ld_plugin_symbol_resolution)Sym.resolution;
if (options::generate_api_file)
*ApiFile << Sym.name << ' ' << getResolutionName(Resolution) << '\n';
if (!GV) {
freeSymName(Sym);
continue; // Asm symbol.
}
ResolutionInfo &Res = ResInfo[Sym.name];
if (Resolution == LDPR_PREVAILING_DEF_IRONLY_EXP && !Res.IsLinkonceOdr)
Resolution = LDPR_PREVAILING_DEF;
// In ThinLTO mode change all prevailing resolutions to LDPR_PREVAILING_DEF.
// For ThinLTO the IR files are compiled through the backend independently,
// so we need to ensure that any prevailing linkonce copy will be emitted
// into the object file by making it weak. Additionally, we can skip the
// IRONLY handling for internalization, which isn't performed in ThinLTO
// mode currently anyway.
if (options::thinlto && (Resolution == LDPR_PREVAILING_DEF_IRONLY_EXP ||
Resolution == LDPR_PREVAILING_DEF_IRONLY))
Resolution = LDPR_PREVAILING_DEF;
GV->setUnnamedAddr(Res.UnnamedAddr);
GV->setVisibility(Res.Visibility);
// Override gold's resolution for common symbols. We want the largest
// one to win.
if (GV->hasCommonLinkage()) {
if (Resolution == LDPR_PREVAILING_DEF_IRONLY)
Res.CommonInternal = true;
if (Resolution == LDPR_PREVAILING_DEF_IRONLY ||
Resolution == LDPR_PREVAILING_DEF)
Res.UseCommon = true;
const DataLayout &DL = GV->getParent()->getDataLayout();
uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType());
unsigned Align = GV->getAlignment();
if (Res.UseCommon && Size >= Res.CommonSize) {
// Take GV.
if (Res.CommonInternal)
Resolution = LDPR_PREVAILING_DEF_IRONLY;
else
Resolution = LDPR_PREVAILING_DEF;
cast<GlobalVariable>(GV)->setAlignment(
std::max(Res.CommonAlign, Align));
} else {
// Do not take GV, it's smaller than what we already have in the
// combined module.
Resolution = LDPR_PREEMPTED_IR;
if (Align > Res.CommonAlign)
// Need to raise the alignment though.
Realign[Sym.name] = Align;
}
Res.CommonSize = std::max(Res.CommonSize, Size);
Res.CommonAlign = std::max(Res.CommonAlign, Align);
}
switch (Resolution) {
//.........这里部分代码省略.........