本文整理汇总了C++中GlobalValue::setLinkage方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue::setLinkage方法的具体用法?C++ GlobalValue::setLinkage怎么用?C++ GlobalValue::setLinkage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalValue
的用法示例。
在下文中一共展示了GlobalValue::setLinkage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeVisible
/// Make sure GV is visible from both modules. Delete is true if it is
/// being deleted from this module.
/// This also makes sure GV cannot be dropped so that references from
/// the split module remain valid.
static void makeVisible(GlobalValue &GV, bool Delete, bool IsDeletePass) {
bool Local = GV.hasLocalLinkage();
if (Local || Delete) {
// This changes members from private -> hidden -> causes linker errors when using llvm-link
if (!IsDeletePass)
GV.setLinkage(GlobalValue::ExternalLinkage);
if (Local)
GV.setVisibility(GlobalValue::HiddenVisibility);
return;
}
if (!GV.hasLinkOnceLinkage()) {
assert(!GV.isDiscardableIfUnused());
return;
}
// Map linkonce* to weak* so that llvm doesn't drop this GV.
switch(GV.getLinkage()) {
default:
llvm_unreachable("Unexpected linkage");
case GlobalValue::LinkOnceAnyLinkage:
GV.setLinkage(GlobalValue::WeakAnyLinkage);
return;
case GlobalValue::LinkOnceODRLinkage:
GV.setLinkage(GlobalValue::WeakODRLinkage);
return;
}
}
示例2: if
GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
bool ForDefinition) {
GlobalValue *NewGV;
if (auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
NewGV = copyGlobalVariableProto(SGVar);
} else if (auto *SF = dyn_cast<Function>(SGV)) {
NewGV = copyFunctionProto(SF);
} else {
if (ForDefinition)
NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
else
NewGV = new GlobalVariable(
DstM, TypeMap.get(SGV->getType()->getElementType()),
/*isConstant*/ false, GlobalValue::ExternalLinkage,
/*init*/ nullptr, SGV->getName(),
/*insertbefore*/ nullptr, SGV->getThreadLocalMode(),
SGV->getType()->getAddressSpace());
}
if (ForDefinition)
NewGV->setLinkage(SGV->getLinkage());
else if (SGV->hasExternalWeakLinkage() || SGV->hasWeakLinkage() ||
SGV->hasLinkOnceLinkage())
NewGV->setLinkage(GlobalValue::ExternalWeakLinkage);
NewGV->copyAttributesFrom(SGV);
return NewGV;
}
示例3: processGlobalForThinLTO
void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
bool DoPromote = false;
if (GV.hasLocalLinkage() &&
((DoPromote = shouldPromoteLocalToGlobal(&GV)) || isPerformingImport())) {
// Once we change the name or linkage it is difficult to determine
// again whether we should promote since shouldPromoteLocalToGlobal needs
// to locate the summary (based on GUID from name and linkage). Therefore,
// use DoPromote result saved above.
GV.setName(getName(&GV, DoPromote));
GV.setLinkage(getLinkage(&GV, DoPromote));
if (!GV.hasLocalLinkage())
GV.setVisibility(GlobalValue::HiddenVisibility);
} else
GV.setLinkage(getLinkage(&GV, /* DoPromote */ false));
// Remove functions imported as available externally defs from comdats,
// as this is a declaration for the linker, and will be dropped eventually.
// It is illegal for comdats to contain declarations.
auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
// The IRMover should not have placed any imported declarations in
// a comdat, so the only declaration that should be in a comdat
// at this point would be a definition imported as available_externally.
assert(GO->hasAvailableExternallyLinkage() &&
"Expected comdat on definition (possibly available external)");
GO->setComdat(nullptr);
}
}
示例4: makeVisible
/// Make sure GV is visible from both modules. Delete is true if it is
/// being deleted from this module.
/// This also makes sure GV cannot be dropped so that references from
/// the split module remain valid.
static void makeVisible(GlobalValue &GV, bool Delete) {
bool Local = GV.hasLocalLinkage();
if (Local)
GV.setVisibility(GlobalValue::HiddenVisibility);
if (Local || Delete) {
GV.setLinkage(GlobalValue::ExternalLinkage);
return;
}
if (!GV.hasLinkOnceLinkage()) {
assert(!GV.isDiscardableIfUnused());
return;
}
// Map linkonce* to weak* so that llvm doesn't drop this GV.
switch(GV.getLinkage()) {
default:
llvm_unreachable("Unexpected linkage");
case GlobalValue::LinkOnceAnyLinkage:
GV.setLinkage(GlobalValue::WeakAnyLinkage);
return;
case GlobalValue::LinkOnceODRLinkage:
GV.setLinkage(GlobalValue::WeakODRLinkage);
return;
}
}
示例5: processGlobalForThinLTO
void ThinLTOGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
if (GV.hasLocalLinkage() &&
(doPromoteLocalToGlobal(&GV) || isPerformingImport())) {
GV.setName(getName(&GV));
GV.setLinkage(getLinkage(&GV));
if (!GV.hasLocalLinkage())
GV.setVisibility(GlobalValue::HiddenVisibility);
if (isModuleExporting())
NewExportedValues.insert(&GV);
return;
}
GV.setLinkage(getLinkage(&GV));
}
示例6: llvm_mark_decl_weak
// llvm_mark_decl_weak - Used by varasm.c, called when a decl is found to be
// weak, but it already had an llvm object created for it. This marks the LLVM
// object weak as well.
void llvm_mark_decl_weak(tree decl) {
assert(DECL_LLVM_SET_P(decl) && DECL_WEAK(decl) &&
isa<GlobalValue>(DECL_LLVM(decl)) && "Decl isn't marked weak!");
GlobalValue *GV = cast<GlobalValue>(DECL_LLVM(decl));
// Do not mark something that is already known to be linkonce or internal.
if (GV->hasExternalLinkage()) {
if (GV->isDeclaration())
GV->setLinkage(GlobalValue::ExternalWeakLinkage);
else
GV->setLinkage(GlobalValue::WeakLinkage);
}
}
示例7: allSymbolsReadHook
/// gold informs us that all symbols have been read. At this point, we use
/// get_symbols to see if any of our definitions have been overridden by a
/// native object file. Then, perform optimization and codegen.
static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
if (Modules.empty())
return LDPS_OK;
LLVMContext Context;
std::unique_ptr<Module> Combined(new Module("ld-temp.o", Context));
Linker L(Combined.get());
std::string DefaultTriple = sys::getDefaultTargetTriple();
StringSet<> Internalize;
StringSet<> Maybe;
for (claimed_file &F : Modules) {
std::unique_ptr<Module> M =
getModuleForFile(Context, F, ApiFile, Internalize, Maybe);
if (!options::triple.empty())
M->setTargetTriple(options::triple.c_str());
else if (M->getTargetTriple().empty()) {
M->setTargetTriple(DefaultTriple);
}
if (L.linkInModule(M.get()))
message(LDPL_FATAL, "Failed to link module");
}
for (const auto &Name : Internalize) {
GlobalValue *GV = Combined->getNamedValue(Name.first());
if (GV)
internalize(*GV);
}
for (const auto &Name : Maybe) {
GlobalValue *GV = Combined->getNamedValue(Name.first());
if (!GV)
continue;
GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
if (canBeOmittedFromSymbolTable(GV))
internalize(*GV);
}
if (options::generate_bc_file != options::BC_NO) {
std::string path;
if (options::generate_bc_file == options::BC_ONLY)
path = output_name;
else
path = output_name + ".bc";
saveBCFile(path, *L.getModule());
if (options::generate_bc_file == options::BC_ONLY)
return LDPS_OK;
}
codegen(*L.getModule());
if (!options::extra_library_path.empty() &&
set_extra_library_path(options::extra_library_path.c_str()) != LDPS_OK)
message(LDPL_FATAL, "Unable to set the extra library path.");
return LDPS_OK;
}
示例8: processGlobalForThinLTO
void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
// Check the summaries to see if the symbol gets resolved to a known local
// definition.
if (GV.hasName()) {
ValueInfo VI = ImportIndex.getValueInfo(GV.getGUID());
if (VI) {
// Need to check all summaries are local in case of hash collisions.
bool IsLocal = VI.getSummaryList().size() &&
llvm::all_of(VI.getSummaryList(),
[](const std::unique_ptr<GlobalValueSummary> &Summary) {
return Summary->isDSOLocal();
});
if (IsLocal)
GV.setDSOLocal(true);
}
}
bool DoPromote = false;
if (GV.hasLocalLinkage() &&
((DoPromote = shouldPromoteLocalToGlobal(&GV)) || isPerformingImport())) {
// Once we change the name or linkage it is difficult to determine
// again whether we should promote since shouldPromoteLocalToGlobal needs
// to locate the summary (based on GUID from name and linkage). Therefore,
// use DoPromote result saved above.
GV.setName(getName(&GV, DoPromote));
GV.setLinkage(getLinkage(&GV, DoPromote));
if (!GV.hasLocalLinkage())
GV.setVisibility(GlobalValue::HiddenVisibility);
} else
GV.setLinkage(getLinkage(&GV, /* DoPromote */ false));
// Remove functions imported as available externally defs from comdats,
// as this is a declaration for the linker, and will be dropped eventually.
// It is illegal for comdats to contain declarations.
auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
// The IRMover should not have placed any imported declarations in
// a comdat, so the only declaration that should be in a comdat
// at this point would be a definition imported as available_externally.
assert(GO->hasAvailableExternallyLinkage() &&
"Expected comdat on definition (possibly available external)");
GO->setComdat(nullptr);
}
}
示例9: 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.");
}
示例10: if
GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
bool ForDefinition) {
GlobalValue *NewGV;
if (auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
NewGV = copyGlobalVariableProto(SGVar);
} else if (auto *SF = dyn_cast<Function>(SGV)) {
NewGV = copyFunctionProto(SF);
} else {
if (ForDefinition)
NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
else
NewGV = new GlobalVariable(
DstM, TypeMap.get(SGV->getValueType()),
/*isConstant*/ false, GlobalValue::ExternalLinkage,
/*init*/ nullptr, SGV->getName(),
/*insertbefore*/ nullptr, SGV->getThreadLocalMode(),
SGV->getType()->getAddressSpace());
}
if (ForDefinition)
NewGV->setLinkage(SGV->getLinkage());
else if (SGV->hasExternalWeakLinkage())
NewGV->setLinkage(GlobalValue::ExternalWeakLinkage);
NewGV->copyAttributesFrom(SGV);
if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
// Metadata for global variables and function declarations is copied eagerly.
if (isa<GlobalVariable>(SGV) || SGV->isDeclaration())
NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
}
// Remove these copied constants in case this stays a declaration, since
// they point to the source module. If the def is linked the values will
// be mapped in during linkFunctionBody.
if (auto *NewF = dyn_cast<Function>(NewGV)) {
NewF->setPersonalityFn(nullptr);
NewF->setPrefixData(nullptr);
NewF->setPrologueData(nullptr);
}
return NewGV;
}
示例11: keepGlobalValue
static void keepGlobalValue(GlobalValue &GV,
std::vector<GlobalAlias *> &KeptAliases) {
assert(!GV.hasLocalLinkage());
if (auto *GA = dyn_cast<GlobalAlias>(&GV))
KeptAliases.push_back(GA);
switch (GV.getLinkage()) {
default:
break;
case GlobalValue::LinkOnceAnyLinkage:
GV.setLinkage(GlobalValue::WeakAnyLinkage);
break;
case GlobalValue::LinkOnceODRLinkage:
GV.setLinkage(GlobalValue::WeakODRLinkage);
break;
}
assert(!GV.isDiscardableIfUnused());
}
示例12: linkFunctionProto
/// linkFunctionProto - Link the function in the source module into the
/// destination module if needed, setting up mapping information.
bool ModuleLinker::linkFunctionProto(Function *SF) {
GlobalValue *DGV = getLinkedToGlobal(SF);
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
if (DGV) {
GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
bool LinkFromSrc = false;
GlobalValue::VisibilityTypes NV;
if (getLinkageResult(DGV, SF, NewLinkage, NV, LinkFromSrc))
return true;
NewVisibility = NV;
if (!LinkFromSrc) {
// Set calculated linkage
DGV->setLinkage(NewLinkage);
DGV->setVisibility(*NewVisibility);
// Make sure to remember this mapping.
ValueMap[SF] = ConstantExpr::getBitCast(DGV, TypeMap.get(SF->getType()));
// Track the function from the source module so we don't attempt to remap
// it.
DoNotLinkFromSource.insert(SF);
return false;
}
}
// If there is no linkage to be performed or we are linking from the source,
// bring SF over.
Function *NewDF = Function::Create(TypeMap.get(SF->getFunctionType()),
SF->getLinkage(), SF->getName(), DstM);
CopyGVAttributes(NewDF, SF);
if (NewVisibility)
NewDF->setVisibility(*NewVisibility);
if (DGV) {
// Any uses of DF need to change to NewDF, with cast.
DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DGV->getType()));
DGV->eraseFromParent();
} else {
// Internal, LO_ODR, or LO linkage - stick in set to ignore and lazily link.
if (SF->hasLocalLinkage() || SF->hasLinkOnceLinkage() ||
SF->hasAvailableExternallyLinkage()) {
DoNotLinkFromSource.insert(SF);
LazilyLinkFunctions.push_back(SF);
}
}
ValueMap[SF] = NewDF;
return false;
}
示例13: linkAliasProto
/// LinkAliasProto - Set up prototypes for any aliases that come over from the
/// source module.
bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
GlobalValue *DGV = getLinkedToGlobal(SGA);
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
if (DGV) {
GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
GlobalValue::VisibilityTypes NV;
bool LinkFromSrc = false;
if (getLinkageResult(DGV, SGA, NewLinkage, NV, LinkFromSrc))
return true;
NewVisibility = NV;
if (!LinkFromSrc) {
// Set calculated linkage.
DGV->setLinkage(NewLinkage);
DGV->setVisibility(*NewVisibility);
// Make sure to remember this mapping.
ValueMap[SGA] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGA->getType()));
// Track the alias from the source module so we don't attempt to remap it.
DoNotLinkFromSource.insert(SGA);
return false;
}
}
// If there is no linkage to be performed or we're linking from the source,
// bring over SGA.
GlobalAlias *NewDA = new GlobalAlias(TypeMap.get(SGA->getType()),
SGA->getLinkage(), SGA->getName(),
/*aliasee*/0, DstM);
CopyGVAttributes(NewDA, SGA);
if (NewVisibility)
NewDA->setVisibility(*NewVisibility);
if (DGV) {
// Any uses of DGV need to change to NewDA, with cast.
DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDA, DGV->getType()));
DGV->eraseFromParent();
}
ValueMap[SGA] = NewDA;
return false;
}
示例14: run
//.........这里部分代码省略.........
const Comdat &C = SMEC.getValue();
if (ComdatsChosen.count(&C))
continue;
Comdat::SelectionKind SK;
bool LinkFromSrc;
if (getComdatResult(&C, SK, LinkFromSrc))
return true;
ComdatsChosen[&C] = std::make_pair(SK, LinkFromSrc);
if (!LinkFromSrc)
continue;
Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable();
Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(C.getName());
if (DstCI == ComdatSymTab.end())
continue;
// The source comdat is replacing the dest one.
const Comdat *DstC = &DstCI->second;
ReplacedDstComdats.insert(DstC);
}
// Alias have to go first, since we are not able to find their comdats
// otherwise.
for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) {
GlobalAlias &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats);
}
for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) {
GlobalVariable &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats);
}
for (auto I = DstM.begin(), E = DstM.end(); I != E;) {
Function &GV = *I++;
dropReplacedComdat(GV, ReplacedDstComdats);
}
for (GlobalVariable &GV : SrcM->globals())
if (GV.hasLinkOnceLinkage())
if (const Comdat *SC = GV.getComdat())
LazyComdatMembers[SC].push_back(&GV);
for (Function &SF : *SrcM)
if (SF.hasLinkOnceLinkage())
if (const Comdat *SC = SF.getComdat())
LazyComdatMembers[SC].push_back(&SF);
for (GlobalAlias &GA : SrcM->aliases())
if (GA.hasLinkOnceLinkage())
if (const Comdat *SC = GA.getComdat())
LazyComdatMembers[SC].push_back(&GA);
// Insert all of the globals in src into the DstM module... without linking
// initializers (which could refer to functions not yet mapped over).
for (GlobalVariable &GV : SrcM->globals())
if (linkIfNeeded(GV))
return true;
for (Function &SF : *SrcM)
if (linkIfNeeded(SF))
return true;
for (GlobalAlias &GA : SrcM->aliases())
if (linkIfNeeded(GA))
return true;
for (unsigned I = 0; I < ValuesToLink.size(); ++I) {
GlobalValue *GV = ValuesToLink[I];
const Comdat *SC = GV->getComdat();
if (!SC)
continue;
for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
GlobalValue *DGV = getLinkedToGlobal(GV2);
bool LinkFromSrc = true;
if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
return true;
if (LinkFromSrc)
ValuesToLink.insert(GV2);
}
}
if (shouldInternalizeLinkedSymbols()) {
for (GlobalValue *GV : ValuesToLink)
Internalize.insert(GV->getName());
}
if (Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
addLazyFor(GV, Add);
}))
return true;
for (auto &P : Internalize) {
GlobalValue *GV = DstM.getNamedValue(P.first());
GV->setLinkage(GlobalValue::InternalLinkage);
}
return false;
}
示例15: BufferRef
//.........这里部分代码省略.........
// 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) {
case LDPR_UNKNOWN:
llvm_unreachable("Unexpected resolution");
case LDPR_RESOLVED_IR:
case LDPR_RESOLVED_EXEC:
case LDPR_RESOLVED_DYN:
case LDPR_PREEMPTED_IR:
case LDPR_PREEMPTED_REG:
break;
case LDPR_UNDEF:
if (!GV->isDeclarationForLinker())
assert(GV->hasComdat());
break;
case LDPR_PREVAILING_DEF_IRONLY: {
Keep.push_back(GV);
// The IR linker has to be able to map this value to a declaration,
// so we can only internalize after linking.
if (!Used.count(GV))
Internalize.insert(GV->getName());
break;
}
case LDPR_PREVAILING_DEF:
Keep.push_back(GV);
// There is a non IR use, so we have to force optimizations to keep this.
switch (GV->getLinkage()) {
default:
break;
case GlobalValue::LinkOnceAnyLinkage:
GV->setLinkage(GlobalValue::WeakAnyLinkage);
break;
case GlobalValue::LinkOnceODRLinkage:
GV->setLinkage(GlobalValue::WeakODRLinkage);
break;
}
break;
case LDPR_PREVAILING_DEF_IRONLY_EXP: {
// We can only check for address uses after we merge the modules. The
// reason is that this GV might have a copy in another module
// and in that module the address might be significant, but that
// copy will be LDPR_PREEMPTED_IR.
Maybe.insert(GV->getName());
Keep.push_back(GV);
break;
}
}
freeSymName(Sym);
}
return Obj.takeModule();
}