本文整理汇总了C++中GlobalValue::isDiscardableIfUnused方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue::isDiscardableIfUnused方法的具体用法?C++ GlobalValue::isDiscardableIfUnused怎么用?C++ GlobalValue::isDiscardableIfUnused使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalValue
的用法示例。
在下文中一共展示了GlobalValue::isDiscardableIfUnused方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 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;
}
}
示例2: 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;
}
}
示例3: 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());
}
示例4: BufferRef
static std::unique_ptr<Module>
getModuleForFile(LLVMContext &Context, claimed_file &F,
ld_plugin_input_file &Info, raw_fd_ostream *ApiFile,
StringSet<> &Internalize, StringSet<> &Maybe) {
if (get_symbols(F.handle, F.syms.size(), F.syms.data()) != LDPS_OK)
message(LDPL_FATAL, "Failed to get symbol information");
const void *View;
if (get_view(F.handle, &View) != LDPS_OK)
message(LDPL_FATAL, "Failed to get a view of file");
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);
DenseSet<GlobalValue *> Drop;
std::vector<GlobalAlias *> KeptAliases;
unsigned SymNum = 0;
for (auto &ObjSym : Obj.symbols()) {
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';
GlobalValue *GV = Obj.getSymbolGV(ObjSym.getRawDataRefImpl());
if (!GV) {
freeSymName(Sym);
continue; // Asm symbol.
}
if (Resolution != LDPR_PREVAILING_DEF_IRONLY && GV->hasCommonLinkage()) {
// Common linkage is special. There is no single symbol that wins the
// resolution. Instead we have to collect the maximum alignment and size.
// The IR linker does that for us if we just pass it every common GV.
// We still have to keep track of LDPR_PREVAILING_DEF_IRONLY so we
// internalize once the IR linker has done its job.
freeSymName(Sym);
continue;
}
switch (Resolution) {
case LDPR_UNKNOWN:
llvm_unreachable("Unexpected resolution");
case LDPR_RESOLVED_IR:
case LDPR_RESOLVED_EXEC:
case LDPR_RESOLVED_DYN:
assert(GV->isDeclarationForLinker());
break;
case LDPR_UNDEF:
if (!GV->isDeclarationForLinker()) {
assert(GV->hasComdat());
Drop.insert(GV);
}
break;
case LDPR_PREVAILING_DEF_IRONLY: {
keepGlobalValue(*GV, KeptAliases);
if (!Used.count(GV)) {
// Since we use the regular lib/Linker, we cannot just internalize GV
// now or it will not be copied to the merged module. Instead we force
// it to be copied and then internalize it.
Internalize.insert(GV->getName());
}
break;
}
case LDPR_PREVAILING_DEF:
keepGlobalValue(*GV, KeptAliases);
break;
case LDPR_PREEMPTED_IR:
// Gold might have selected a linkonce_odr and preempted a weak_odr.
// In that case we have to make sure we don't end up internalizing it.
if (!GV->isDiscardableIfUnused())
Maybe.erase(GV->getName());
//.........这里部分代码省略.........