本文整理汇总了C++中GlobalAlias::replaceAllUsesWith方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalAlias::replaceAllUsesWith方法的具体用法?C++ GlobalAlias::replaceAllUsesWith怎么用?C++ GlobalAlias::replaceAllUsesWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalAlias
的用法示例。
在下文中一共展示了GlobalAlias::replaceAllUsesWith方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnModule
bool ResolveAliases::runOnModule(Module &M) {
bool Modified = false;
for (auto I = M.alias_begin(), E = M.alias_end(); I != E;) {
GlobalAlias *Alias = &*I++;
Alias->replaceAllUsesWith(Alias->getAliasee());
Alias->eraseFromParent();
Modified = true;
}
return Modified;
}
示例2: convertAliasToDeclaration
static void convertAliasToDeclaration(GlobalAlias &GA, Module &M) {
GlobalValue *GVal = GA.getBaseObject();
GlobalValue *NewGV;
if (auto *GVar = dyn_cast<GlobalVariable>(GVal)) {
GlobalVariable *NewGVar = new GlobalVariable(
M, GVar->getType()->getElementType(), GVar->isConstant(),
GVar->getLinkage(), /*init*/ nullptr, GA.getName(), GVar,
GVar->getThreadLocalMode(), GVar->getType()->getAddressSpace());
NewGV = NewGVar;
NewGV->copyAttributesFrom(GVar);
} else {
auto *F = dyn_cast<Function>(GVal);
assert(F);
Function *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
GA.getName(), &M);
NewGV = NewF;
NewGV->copyAttributesFrom(F);
}
GA.replaceAllUsesWith(ConstantExpr::getBitCast(NewGV, GA.getType()));
GA.eraseFromParent();
}
示例3: jl_merge_module
// destructively move the contents of src into dest
// this assumes that the targets of the two modules are the same
// including the DataLayout and ModuleFlags (for example)
// and that there is no module-level assembly
static void jl_merge_module(Module *dest, std::unique_ptr<Module> src)
{
assert(dest != src.get());
for (Module::global_iterator I = src->global_begin(), E = src->global_end(); I != E;) {
GlobalVariable *sG = &*I;
GlobalValue *dG = dest->getNamedValue(sG->getName());
++I;
// Replace a declaration with the definition:
if (dG) {
if (sG->isDeclaration()) {
sG->replaceAllUsesWith(dG);
sG->eraseFromParent();
continue;
}
else {
dG->replaceAllUsesWith(sG);
dG->eraseFromParent();
}
}
// Reparent the global variable:
sG->removeFromParent();
dest->getGlobalList().push_back(sG);
// Comdat is owned by the Module, recreate it in the new parent:
addComdat(sG);
}
for (Module::iterator I = src->begin(), E = src->end(); I != E;) {
Function *sG = &*I;
GlobalValue *dG = dest->getNamedValue(sG->getName());
++I;
// Replace a declaration with the definition:
if (dG) {
if (sG->isDeclaration()) {
sG->replaceAllUsesWith(dG);
sG->eraseFromParent();
continue;
}
else {
dG->replaceAllUsesWith(sG);
dG->eraseFromParent();
}
}
// Reparent the global variable:
sG->removeFromParent();
dest->getFunctionList().push_back(sG);
// Comdat is owned by the Module, recreate it in the new parent:
addComdat(sG);
}
for (Module::alias_iterator I = src->alias_begin(), E = src->alias_end(); I != E;) {
GlobalAlias *sG = &*I;
GlobalValue *dG = dest->getNamedValue(sG->getName());
++I;
if (dG) {
if (!dG->isDeclaration()) { // aliases are always definitions, so this test is reversed from the above two
sG->replaceAllUsesWith(dG);
sG->eraseFromParent();
continue;
}
else {
dG->replaceAllUsesWith(sG);
dG->eraseFromParent();
}
}
sG->removeFromParent();
dest->getAliasList().push_back(sG);
}
// metadata nodes need to be explicitly merged not just copied
// so there are special passes here for each known type of metadata
NamedMDNode *sNMD = src->getNamedMetadata("llvm.dbg.cu");
if (sNMD) {
NamedMDNode *dNMD = dest->getOrInsertNamedMetadata("llvm.dbg.cu");
#ifdef LLVM35
for (NamedMDNode::op_iterator I = sNMD->op_begin(), E = sNMD->op_end(); I != E; ++I) {
dNMD->addOperand(*I);
}
#else
for (unsigned i = 0, l = sNMD->getNumOperands(); i < l; i++) {
dNMD->addOperand(sNMD->getOperand(i));
}
#endif
}
}