本文整理汇总了C++中GlobalValue::getName方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue::getName方法的具体用法?C++ GlobalValue::getName怎么用?C++ GlobalValue::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalValue
的用法示例。
在下文中一共展示了GlobalValue::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
ArrayRef<StringRef> Libcalls,
std::vector<const char*> &MustPreserveList,
SmallPtrSetImpl<GlobalValue*> &AsmUsed,
Mangler &Mangler) {
// There are no restrictions to apply to declarations.
if (GV.isDeclaration())
return;
// There is nothing more restrictive than private linkage.
if (GV.hasPrivateLinkage())
return;
SmallString<64> Buffer;
TargetMach->getNameWithPrefix(Buffer, &GV, Mangler);
if (MustPreserveSymbols.count(Buffer))
MustPreserveList.push_back(GV.getName().data());
if (AsmUndefinedRefs.count(Buffer))
AsmUsed.insert(&GV);
// Conservatively append user-supplied runtime library functions to
// llvm.compiler.used. These could be internalized and deleted by
// optimizations like -globalopt, causing problems when later optimizations
// add new library calls (e.g., llvm.memset => memset and printf => puts).
// Leave it to the linker to remove any dead code (e.g. with -dead_strip).
if (isa<Function>(GV) &&
std::binary_search(Libcalls.begin(), Libcalls.end(), GV.getName()))
AsmUsed.insert(&GV);
}
示例2: DumpSymbolNameForGlobalValue
static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
// Private linkage and available_externally linkage don't exist in symtab.
if (GV.hasPrivateLinkage() || GV.hasLinkerPrivateLinkage() ||
GV.hasLinkerPrivateWeakLinkage() || GV.hasAvailableExternallyLinkage())
return;
const std::string SymbolAddrStr = " "; // Not used yet...
char TypeChar = TypeCharForSymbol(GV);
if ((TypeChar != 'U') && UndefinedOnly)
return;
if ((TypeChar == 'U') && DefinedOnly)
return;
if (GV.hasLocalLinkage () && ExternalOnly)
return;
if (OutputFormat == posix) {
outs() << GV.getName () << " " << TypeCharForSymbol(GV) << " "
<< SymbolAddrStr << "\n";
} else if (OutputFormat == bsd) {
outs() << SymbolAddrStr << " " << TypeCharForSymbol(GV) << " "
<< GV.getName () << "\n";
} else if (OutputFormat == sysv) {
std::string PaddedName (GV.getName ());
while (PaddedName.length () < 20)
PaddedName += " ";
outs() << PaddedName << "|" << SymbolAddrStr << "| "
<< TypeCharForSymbol(GV)
<< " | | | |\n";
}
}
示例3: shouldInternalize
static bool shouldInternalize(const GlobalValue &GV,
const std::set<std::string> &ExternalNames,
const std::set<std::string> &DSONames) {
// Function must be defined here
if (GV.isDeclaration())
return false;
// Available externally is really just a "declaration with a body".
if (GV.hasAvailableExternallyLinkage())
return false;
// Already has internal linkage
if (GV.hasLocalLinkage())
return false;
// Marked to keep external?
if (ExternalNames.count(GV.getName()))
return false;
// Not needed for the symbol table?
if (!DSONames.count(GV.getName()))
return true;
// Not a linkonce. Someone can depend on it being on the symbol table.
if (!GV.hasLinkOnceLinkage())
return false;
// The address is not important, we can hide it.
if (GV.hasUnnamedAddr())
return true;
// FIXME: Check if the address is used.
return false;
}
示例4: addLazyFor
void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
if (!shouldLinkReferencedLinkOnce())
// For ThinLTO we don't import more than what was required.
// The client has to guarantee that the linkonce will be availabe at link
// time (by promoting it to weak for instance).
return;
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded())
return;
if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV.getName());
Add(GV);
const Comdat *SC = GV.getComdat();
if (!SC)
return;
for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
GlobalValue *DGV = getLinkedToGlobal(GV2);
bool LinkFromSrc = true;
if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
return;
if (!LinkFromSrc)
continue;
if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV2->getName());
Add(*GV2);
}
}
示例5: shouldInternalize
static bool shouldInternalize(const GlobalValue &GV,
const std::set<std::string> &ExternalNames,
bool OnlyHidden) {
if (OnlyHidden && !GV.hasHiddenVisibility())
return false;
// Function must be defined here
if (GV.isDeclaration())
return false;
// Available externally is really just a "declaration with a body".
if (GV.hasAvailableExternallyLinkage())
return false;
// Assume that dllexported symbols are referenced elsewhere
if (GV.hasDLLExportStorageClass())
return false;
// Already has internal linkage
if (GV.hasLocalLinkage())
return false;
// Marked to keep external?
if (ExternalNames.count(GV.getName()))
return false;
return true;
}
示例6:
void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
std::vector<const char*> &MustPreserveList,
std::vector<const char*> &DSOList,
SmallPtrSet<GlobalValue*, 8> &AsmUsed,
Mangler &Mangler) {
SmallString<64> Buffer;
Mangler.getNameWithPrefix(Buffer, &GV, false);
if (GV.isDeclaration())
return;
if (MustPreserveSymbols.count(Buffer))
MustPreserveList.push_back(GV.getName().data());
if (DSOSymbols.count(Buffer))
DSOList.push_back(GV.getName().data());
if (AsmUndefinedRefs.count(Buffer))
AsmUsed.insert(&GV);
}
示例7: assert
Module * llvmutil_extractmodule(Module * OrigMod, TargetMachine * TM, std::vector<llvm::GlobalValue*> * livevalues, std::vector<std::string> * symbolnames, bool internalizeandoptimize) {
assert(symbolnames == NULL || livevalues->size() == symbolnames->size());
ValueToValueMapTy VMap;
#if LLVM_VERSION >= 34
Module * M = llvmutil_extractmodulewithproperties(OrigMod->getModuleIdentifier(), OrigMod, (llvm::GlobalValue **)&(*livevalues)[0], livevalues->size(), AlwaysCopy, NULL, VMap);
#else
Module * M = CloneModule(OrigMod, VMap);
internalizeandoptimize = true; //we need to do this regardless of the input because it is the only way we can extract just the needed functions from the module
#endif
//rename values to symbolsnames
std::vector<const char *> names;
for(size_t i = 0; i < livevalues->size(); i++) {
GlobalValue * fn = cast<GlobalValue>(VMap[(*livevalues)[i]]);
const std::string & name = (*symbolnames)[i];
GlobalValue * gv = M->getNamedValue(name);
if(gv) { //if there is already a symbol with this name, rename it
gv->setName(Twine((*symbolnames)[i],"_renamed"));
}
fn->setName(name); //and set our function to this name
assert(fn->getName() == name);
names.push_back(name.c_str()); //internalize pass has weird interface, so we need to copy the names here
}
if (!internalizeandoptimize)
return M;
//at this point we run optimizations on the module
//first internalize all functions not mentioned in "names" using an internalize pass and then perform
//standard optimizations
PassManager MPM;
llvmutil_addtargetspecificpasses(&MPM, TM);
MPM.add(createVerifierPass()); //make sure we haven't messed stuff up yet
MPM.add(createInternalizePass(names));
MPM.add(createGlobalDCEPass()); //run this early since anything not in the table of exported functions is still in this module
//this will remove dead functions
PassManagerBuilder PMB;
PMB.OptLevel = 3;
PMB.SizeLevel = 0;
#if LLVM_VERSION >= 35
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
#endif
PMB.populateModulePassManager(MPM);
MPM.run(*M);
return M;
}
示例8: changeGlobal
void Variables::changeGlobal(Change* change, Module &module) {
GlobalValue* oldTarget = dyn_cast<GlobalValue>(change->getValue());
Type* oldType = oldTarget->getType()->getElementType();
Type* newType = change->getType()[0];
errs() << "Changing the precision of variable \"" << oldTarget->getName() << "\" from " << *oldType << " to " << *newType << ".\n";
if (diffTypes(oldType, newType)) {
Constant *initializer;
GlobalVariable* newTarget;
if (PointerType *newPointerType = dyn_cast<PointerType>(newType)) {
initializer = ConstantPointerNull::get(newPointerType);
newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
}
else if (ArrayType * atype = dyn_cast<ArrayType>(newType)) {
// preparing initializer
Type *temp = Type::getFloatTy(module.getContext());
vector<Constant*> operands;
operands.push_back(ConstantFP::get(temp, 0));
ArrayRef<Constant*> *arrayRef = new ArrayRef<Constant*>(operands);
initializer = ConstantArray::get(atype, *arrayRef);
newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
}
else {
initializer = ConstantFP::get(newType, 0);
newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
}
/*
GlobalVariable* newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
*/
unsigned alignment = getAlignment(newType);
newTarget->setAlignment(alignment);
newTarget->takeName(oldTarget);
// iterating through instructions using old AllocaInst
Value::use_iterator it = oldTarget->use_begin();
for(; it != oldTarget->use_end(); it++) {
Transformer::transform(it, newTarget, oldTarget, newType, oldType, alignment);
}
//oldTarget->eraseFromParent();
}
else {
errs() << "No changes required.\n";
}
return;
}
示例9: DumpSymbolNameForGlobalValue
static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
const std::string SymbolAddrStr = " "; // Not used yet...
char TypeChar = TypeCharForSymbol (GV);
if ((TypeChar != 'U') && UndefinedOnly)
return;
if ((TypeChar == 'U') && DefinedOnly)
return;
if (GV.hasLocalLinkage () && ExternalOnly)
return;
if (OutputFormat == posix) {
std::cout << GV.getName () << " " << TypeCharForSymbol (GV) << " "
<< SymbolAddrStr << "\n";
} else if (OutputFormat == bsd) {
std::cout << SymbolAddrStr << " " << TypeCharForSymbol (GV) << " "
<< GV.getName () << "\n";
} else if (OutputFormat == sysv) {
std::string PaddedName (GV.getName ());
while (PaddedName.length () < 20)
PaddedName += " ";
std::cout << PaddedName << "|" << SymbolAddrStr << "| "
<< TypeCharForSymbol (GV)
<< " | | | |\n";
}
}
示例10: DumpSymbolNameForGlobalValue
static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
// Private linkage and available_externally linkage don't exist in symtab.
if (GV.hasPrivateLinkage() ||
GV.hasLinkerPrivateLinkage() ||
GV.hasLinkerPrivateWeakLinkage() ||
GV.hasAvailableExternallyLinkage())
return;
char TypeChar = TypeCharForSymbol(GV);
if (GV.hasLocalLinkage () && ExternalOnly)
return;
NMSymbol s;
s.Address = object::UnknownAddressOrSize;
s.Size = object::UnknownAddressOrSize;
s.TypeChar = TypeChar;
s.Name = GV.getName();
SymbolList.push_back(s);
}
示例11: addLazyFor
void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage())
return;
if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV.getName());
Add(GV);
const Comdat *SC = GV.getComdat();
if (!SC)
return;
for (GlobalValue *GV2 : ComdatMembers[SC]) {
if (!GV2->hasLocalLinkage() && shouldInternalizeLinkedSymbols())
Internalize.insert(GV2->getName());
Add(*GV2);
}
}
示例12: doInitialization
bool UnsafeTypeCastingCheck::doInitialization(llvm::Module &mod) {
errs() << "initialization... \n";
for (Module::global_iterator git = mod.global_begin() ;
git != mod.global_end() ;
git++) {
GlobalValue *gv = dyn_cast<GlobalValue>(git);
string gv_name = gv->getName().str();
if (gv_name.compare("blockDim") == 0 ||
gv_name.compare("gridDim") == 0 ||
gv_name.compare("blockIdx") == 0 ||
gv_name.compare("threadIdx") == 0) {
setPointedType(gv, UINT_UT);
}
}
// get utcc_assert function call (assertion)
code_modified = false;
assert_func = mod.getFunction("utcc_assert");
assert(assert_func != NULL);
return false;
}
示例13: addLazyFor
void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage())
return;
if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV.getName());
Add(GV);
const Comdat *SC = GV.getComdat();
if (!SC)
return;
for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
GlobalValue *DGV = getLinkedToGlobal(GV2);
bool LinkFromSrc = true;
if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
return;
if (!LinkFromSrc)
continue;
if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV2->getName());
Add(*GV2);
}
}
示例14: add
void BitcodeCompiler::add(BitcodeFile &F) {
std::unique_ptr<IRObjectFile> Obj = std::move(F.Obj);
std::vector<GlobalValue *> Keep;
unsigned BodyIndex = 0;
ArrayRef<Symbol *> Syms = F.getSymbols();
Module &M = Obj->getModule();
if (M.getDataLayoutStr().empty())
fatal("invalid bitcode file: " + F.getName() + " has no datalayout");
// Discard non-compatible debug infos if necessary.
M.materializeMetadata();
UpgradeDebugInfo(M);
// If a symbol appears in @llvm.used, the linker is required
// to treat the symbol as there is a reference to the symbol
// that it cannot see. Therefore, we can't internalize.
SmallPtrSet<GlobalValue *, 8> Used;
collectUsedGlobalVariables(M, Used, /* CompilerUsed */ false);
for (const BasicSymbolRef &Sym : Obj->symbols()) {
uint32_t Flags = Sym.getFlags();
GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
if (GV && GV->hasAppendingLinkage())
Keep.push_back(GV);
if (BitcodeFile::shouldSkip(Flags))
continue;
Symbol *S = Syms[BodyIndex++];
if (Flags & BasicSymbolRef::SF_Undefined) {
handleUndefinedAsmRefs(Sym, GV, AsmUndefinedRefs);
continue;
}
auto *B = dyn_cast<DefinedBitcode>(S->body());
if (!B || B->File != &F)
continue;
// We collect the set of symbols we want to internalize here
// and change the linkage after the IRMover executed, i.e. after
// we imported the symbols and satisfied undefined references
// to it. We can't just change linkage here because otherwise
// the IRMover will just rename the symbol.
if (GV && shouldInternalize(Used, S, GV))
InternalizedSyms.insert(GV->getName());
// At this point we know that either the combined LTO object will provide a
// definition of a symbol, or we will internalize it. In either case, we
// need to undefine the symbol. In the former case, the real definition
// needs to be able to replace the original definition without conflicting.
// In the latter case, we need to allow the combined LTO object to provide a
// definition with the same name, for example when doing parallel codegen.
undefine(S);
if (!GV)
// Module asm symbol.
continue;
switch (GV->getLinkage()) {
default:
break;
case llvm::GlobalValue::LinkOnceAnyLinkage:
GV->setLinkage(GlobalValue::WeakAnyLinkage);
break;
case llvm::GlobalValue::LinkOnceODRLinkage:
GV->setLinkage(GlobalValue::WeakODRLinkage);
break;
}
Keep.push_back(GV);
}
if (Error E = Mover.move(Obj->takeModule(), Keep,
[](GlobalValue &, IRMover::ValueAdder) {})) {
handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) {
fatal("failed to link module " + F.getName() + ": " + EIB.message());
});
}
}
示例15: shouldLinkFromSource
//.........这里部分代码省略.........
if (Src.hasAppendingLinkage()) {
// Should have prevented importing for appending linkage in linkIfNeeded.
assert(!isPerformingImport());
LinkFromSrc = true;
return false;
}
bool SrcIsDeclaration = Src.isDeclarationForLinker();
bool DestIsDeclaration = Dest.isDeclarationForLinker();
if (isPerformingImport()) {
if (isa<Function>(&Src)) {
// For functions, LinkFromSrc iff this is a function requested
// for importing. For variables, decide below normally.
LinkFromSrc = GlobalsToImport->count(&Src);
return false;
}
// Check if this is an alias with an already existing definition
// in Dest, which must have come from a prior importing pass from
// the same Src module. Unlike imported function and variable
// definitions, which are imported as available_externally and are
// not definitions for the linker, that is not a valid linkage for
// imported aliases which must be definitions. Simply use the existing
// Dest copy.
if (isa<GlobalAlias>(&Src) && !DestIsDeclaration) {
assert(isa<GlobalAlias>(&Dest));
LinkFromSrc = false;
return false;
}
}
if (SrcIsDeclaration) {
// If Src is external or if both Src & Dest are external.. Just link the
// external globals, we aren't adding anything.
if (Src.hasDLLImportStorageClass()) {
// If one of GVs is marked as DLLImport, result should be dllimport'ed.
LinkFromSrc = DestIsDeclaration;
return false;
}
// If the Dest is weak, use the source linkage.
if (Dest.hasExternalWeakLinkage()) {
LinkFromSrc = true;
return false;
}
// Link an available_externally over a declaration.
LinkFromSrc = !Src.isDeclaration() && Dest.isDeclaration();
return false;
}
if (DestIsDeclaration) {
// If Dest is external but Src is not:
LinkFromSrc = true;
return false;
}
if (Src.hasCommonLinkage()) {
if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) {
LinkFromSrc = true;
return false;
}
if (!Dest.hasCommonLinkage()) {
LinkFromSrc = false;
return false;
}
const DataLayout &DL = Dest.getParent()->getDataLayout();
uint64_t DestSize = DL.getTypeAllocSize(Dest.getValueType());
uint64_t SrcSize = DL.getTypeAllocSize(Src.getValueType());
LinkFromSrc = SrcSize > DestSize;
return false;
}
if (Src.isWeakForLinker()) {
assert(!Dest.hasExternalWeakLinkage());
assert(!Dest.hasAvailableExternallyLinkage());
if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage()) {
LinkFromSrc = true;
return false;
}
LinkFromSrc = false;
return false;
}
if (Dest.isWeakForLinker()) {
assert(Src.hasExternalLinkage());
LinkFromSrc = true;
return false;
}
assert(!Src.hasExternalWeakLinkage());
assert(!Dest.hasExternalWeakLinkage());
assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() &&
"Unexpected linkage type!");
return emitError("Linking globals named '" + Src.getName() +
"': symbol multiply defined!");
}