本文整理汇总了C++中MDNode::replaceAllUsesWith方法的典型用法代码示例。如果您正苦于以下问题:C++ MDNode::replaceAllUsesWith方法的具体用法?C++ MDNode::replaceAllUsesWith怎么用?C++ MDNode::replaceAllUsesWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDNode
的用法示例。
在下文中一共展示了MDNode::replaceAllUsesWith方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replaceOperand
// Replace value from this node's operand list.
void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
Value *From = *Op;
// If is possible that someone did GV->RAUW(inst), replacing a global variable
// with an instruction or some other function-local object. If this is a
// non-function-local MDNode, it can't point to a function-local object.
// Handle this case by implicitly dropping the MDNode reference to null.
if (!isFunctionLocal() && To && isFunctionLocalValue(To))
To = 0;
if (From == To)
return;
// Update the operand.
Op->set(To);
// If this node is already not being uniqued (because one of the operands
// already went to null), then there is nothing else to do here.
if (isNotUniqued()) return;
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
// Remove "this" from the context map. FoldingSet doesn't have to reprofile
// this node to remove it, so we don't care what state the operands are in.
pImpl->MDNodeSet.RemoveNode(this);
// If we are dropping an argument to null, we choose to not unique the MDNode
// anymore. This commonly occurs during destruction, and uniquing these
// brings little reuse.
if (To == 0) {
setIsNotUniqued();
return;
}
// Now that the node is out of the folding set, get ready to reinsert it.
// First, check to see if another node with the same operands already exists
// in the set. If it doesn't exist, this returns the position to insert it.
FoldingSetNodeID ID;
Profile(ID);
void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (N) {
N->replaceAllUsesWith(this);
N->destroy();
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
assert(N == 0 && "shouldn't be in the map now!"); (void)N;
}
// InsertPoint will have been set by the FindNodeOrInsertPos call.
pImpl->MDNodeSet.InsertNode(this, InsertPoint);
}
示例2: replaceAllUsesWith
/// replaceAllUsesWith - Replace all uses of debug info referenced by
/// this descriptor.
void DIType::replaceAllUsesWith(MDNode *D) {
if (!DbgNode)
return;
// Since we use a TrackingVH for the node, its easy for clients to manufacture
// legitimate situations where they want to replaceAllUsesWith() on something
// which, due to uniquing, has merged with the source. We shield clients from
// this detail by allowing a value to be replaced with replaceAllUsesWith()
// itself.
if (DbgNode != D) {
MDNode *Node = const_cast<MDNode*>(DbgNode);
const MDNode *DN = D;
const Value *V = cast_or_null<Value>(DN);
Node->replaceAllUsesWith(const_cast<Value*>(V));
MDNode::deleteTemporary(Node);
}
}
示例3: MapValue
Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper) {
ValueToValueMapTy::iterator I = VM.find(V);
// If the value already exists in the map, use it.
if (I != VM.end() && I->second) return I->second;
// Global values do not need to be seeded into the VM if they
// are using the identity mapping.
if (isa<GlobalValue>(V) || isa<MDString>(V))
return VM[V] = const_cast<Value*>(V);
if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
// Inline asm may need *type* remapping.
FunctionType *NewTy = IA->getFunctionType();
if (TypeMapper) {
NewTy = cast<FunctionType>(TypeMapper->remapType(NewTy));
if (NewTy != IA->getFunctionType())
V = InlineAsm::get(NewTy, IA->getAsmString(), IA->getConstraintString(),
IA->hasSideEffects(), IA->isAlignStack());
}
return VM[V] = const_cast<Value*>(V);
}
if (const MDNode *MD = dyn_cast<MDNode>(V)) {
// If this is a module-level metadata and we know that nothing at the module
// level is changing, then use an identity mapping.
if (!MD->isFunctionLocal() && (Flags & RF_NoModuleLevelChanges))
return VM[V] = const_cast<Value*>(V);
// Create a dummy node in case we have a metadata cycle.
MDNode *Dummy = MDNode::getTemporary(V->getContext(), ArrayRef<Value*>());
VM[V] = Dummy;
// Check all operands to see if any need to be remapped.
for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i) {
Value *OP = MD->getOperand(i);
if (OP == 0 || MapValue(OP, VM, Flags, TypeMapper) == OP) continue;
// Ok, at least one operand needs remapping.
SmallVector<Value*, 4> Elts;
Elts.reserve(MD->getNumOperands());
for (i = 0; i != e; ++i) {
Value *Op = MD->getOperand(i);
Elts.push_back(Op ? MapValue(Op, VM, Flags, TypeMapper) : 0);
}
MDNode *NewMD = MDNode::get(V->getContext(), Elts);
Dummy->replaceAllUsesWith(NewMD);
VM[V] = NewMD;
MDNode::deleteTemporary(Dummy);
return NewMD;
}
VM[V] = const_cast<Value*>(V);
MDNode::deleteTemporary(Dummy);
// No operands needed remapping. Use an identity mapping.
return const_cast<Value*>(V);
}
// Okay, this either must be a constant (which may or may not be mappable) or
// is something that is not in the mapping table.
Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V));
if (C == 0)
return 0;
if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
Function *F =
cast<Function>(MapValue(BA->getFunction(), VM, Flags, TypeMapper));
BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(), VM,
Flags, TypeMapper));
return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock());
}
// Otherwise, we have some other constant to remap. Start by checking to see
// if all operands have an identity remapping.
unsigned OpNo = 0, NumOperands = C->getNumOperands();
Value *Mapped = 0;
for (; OpNo != NumOperands; ++OpNo) {
Value *Op = C->getOperand(OpNo);
Mapped = MapValue(Op, VM, Flags, TypeMapper);
if (Mapped != C) break;
}
// See if the type mapper wants to remap the type as well.
Type *NewTy = C->getType();
if (TypeMapper)
NewTy = TypeMapper->remapType(NewTy);
// If the result type and all operands match up, then just insert an identity
// mapping.
if (OpNo == NumOperands && NewTy == C->getType())
return VM[V] = C;
// Okay, we need to create a new constant. We've already processed some or
// all of the operands, set them all up now.
SmallVector<Constant*, 8> Ops;
//.........这里部分代码省略.........
示例4: replaceOperand
// Replace value from this node's operand list.
void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
Value *From = *Op;
// If is possible that someone did GV->RAUW(inst), replacing a global variable
// with an instruction or some other function-local object. If this is a
// non-function-local MDNode, it can't point to a function-local object.
// Handle this case by implicitly dropping the MDNode reference to null.
// Likewise if the MDNode is function-local but for a different function.
if (To && isFunctionLocalValue(To)) {
if (!isFunctionLocal())
To = 0;
else {
const Function *F = getFunction();
const Function *FV = getFunctionForValue(To);
// Metadata can be function-local without having an associated function.
// So only consider functions to have changed if non-null.
if (F && FV && F != FV)
To = 0;
}
}
if (From == To)
return;
// Update the operand.
Op->set(To);
// If this node is already not being uniqued (because one of the operands
// already went to null), then there is nothing else to do here.
if (isNotUniqued()) return;
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
// Remove "this" from the context map. FoldingSet doesn't have to reprofile
// this node to remove it, so we don't care what state the operands are in.
pImpl->MDNodeSet.RemoveNode(this);
// If we are dropping an argument to null, we choose to not unique the MDNode
// anymore. This commonly occurs during destruction, and uniquing these
// brings little reuse. Also, this means we don't need to include
// isFunctionLocal bits in FoldingSetNodeIDs for MDNodes.
if (To == 0) {
setIsNotUniqued();
return;
}
// Now that the node is out of the folding set, get ready to reinsert it.
// First, check to see if another node with the same operands already exists
// in the set. If it doesn't exist, this returns the position to insert it.
FoldingSetNodeID ID;
Profile(ID);
void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (N) {
N->replaceAllUsesWith(this);
N->destroy();
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
assert(N == 0 && "shouldn't be in the map now!"); (void)N;
}
// InsertPoint will have been set by the FindNodeOrInsertPos call.
pImpl->MDNodeSet.InsertNode(this, InsertPoint);
// If this MDValue was previously function-local but no longer is, clear
// its function-local flag.
if (isFunctionLocal() && !isFunctionLocalValue(To)) {
bool isStillFunctionLocal = false;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Value *V = getOperand(i);
if (!V) continue;
if (isFunctionLocalValue(V)) {
isStillFunctionLocal = true;
break;
}
}
if (!isStillFunctionLocal)
setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
}
}
示例5: MapValue
Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM,
RemapFlags Flags) {
ValueToValueMapTy::iterator I = VM.find(V);
// If the value already exists in the map, use it.
if (I != VM.end() && I->second) return I->second;
// Global values do not need to be seeded into the VM if they
// are using the identity mapping.
if (isa<GlobalValue>(V) || isa<InlineAsm>(V) || isa<MDString>(V))
return VM[V] = const_cast<Value*>(V);
if (const MDNode *MD = dyn_cast<MDNode>(V)) {
// If this is a module-level metadata and we know that nothing at the module
// level is changing, then use an identity mapping.
if (!MD->isFunctionLocal() && (Flags & RF_NoModuleLevelChanges))
return VM[V] = const_cast<Value*>(V);
// Create a dummy node in case we have a metadata cycle.
MDNode *Dummy = MDNode::getTemporary(V->getContext(), 0, 0);
VM[V] = Dummy;
// Check all operands to see if any need to be remapped.
for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i) {
Value *OP = MD->getOperand(i);
if (OP == 0 || MapValue(OP, VM, Flags) == OP) continue;
// Ok, at least one operand needs remapping.
SmallVector<Value*, 4> Elts;
Elts.reserve(MD->getNumOperands());
for (i = 0; i != e; ++i) {
Value *Op = MD->getOperand(i);
Elts.push_back(Op ? MapValue(Op, VM, Flags) : 0);
}
MDNode *NewMD = MDNode::get(V->getContext(), Elts.data(), Elts.size());
Dummy->replaceAllUsesWith(NewMD);
VM[V] = NewMD;
MDNode::deleteTemporary(Dummy);
return NewMD;
}
VM[V] = const_cast<Value*>(V);
MDNode::deleteTemporary(Dummy);
// No operands needed remapping. Use an identity mapping.
return const_cast<Value*>(V);
}
// Okay, this either must be a constant (which may or may not be mappable) or
// is something that is not in the mapping table.
Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V));
if (C == 0)
return 0;
if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
Function *F = cast<Function>(MapValue(BA->getFunction(), VM, Flags));
BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(), VM,
Flags));
return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock());
}
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
Value *Op = C->getOperand(i);
Value *Mapped = MapValue(Op, VM, Flags);
if (Mapped == C) continue;
// Okay, the operands don't all match. We've already processed some or all
// of the operands, set them up now.
std::vector<Constant*> Ops;
Ops.reserve(C->getNumOperands());
for (unsigned j = 0; j != i; ++j)
Ops.push_back(cast<Constant>(C->getOperand(i)));
Ops.push_back(cast<Constant>(Mapped));
// Map the rest of the operands that aren't processed yet.
for (++i; i != e; ++i)
Ops.push_back(cast<Constant>(MapValue(C->getOperand(i), VM, Flags)));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
return VM[V] = CE->getWithOperands(Ops);
if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
return VM[V] = ConstantArray::get(CA->getType(), Ops);
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C))
return VM[V] = ConstantStruct::get(CS->getType(), Ops);
assert(isa<ConstantVector>(C) && "Unknown mapped constant type");
return VM[V] = ConstantVector::get(Ops);
}
// If we reach here, all of the operands of the constant match.
return VM[V] = C;
}