本文整理汇总了C++中GlobalValue::use_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalValue::use_begin方法的具体用法?C++ GlobalValue::use_begin怎么用?C++ GlobalValue::use_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalValue
的用法示例。
在下文中一共展示了GlobalValue::use_begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}