本文整理汇总了C++中MDNode::replaceOperandWith方法的典型用法代码示例。如果您正苦于以下问题:C++ MDNode::replaceOperandWith方法的具体用法?C++ MDNode::replaceOperandWith怎么用?C++ MDNode::replaceOperandWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDNode
的用法示例。
在下文中一共展示了MDNode::replaceOperandWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUnrollID
void setUnrollID(Loop *L, bool enable) {
if (!enable && disabledLoops.find(L) != disabledLoops.end())
return;
LLVMContext &Context = L->getHeader()->getContext();
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
SmallVector<Metadata *, 2> forceUnroll;
forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
forceUnroll.push_back(ConstantAsMetadata::get(ConstantInt::get(Type::getInt1Ty(Context), enable)));
MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll);
SmallVector<Metadata *, 4> Vals;
Vals.push_back(NULL);
Vals.push_back(forceUnrollNode);
#else
SmallVector<Value *, 2> forceUnroll;
forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
forceUnroll.push_back(ConstantInt::get(Type::getInt1Ty(Context), enable));
MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll);
SmallVector<Value *, 4> Vals;
Vals.push_back(NULL);
Vals.push_back(forceUnrollNode);
#endif
MDNode *NewLoopID = MDNode::get(Context, Vals);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);
L->setLoopID(NewLoopID);
if (!enable)
disabledLoops.insert(L);
}
示例2: remapOperands
/// Remap the operands of an MDNode.
///
/// If \c Node is temporary, uniquing cycles are ignored. If \c Node is
/// distinct, uniquing cycles are resolved as they're found.
///
/// \pre \c Node.isDistinct() or \c Node.isTemporary().
static bool remapOperands(MDNode &Node,
SmallVectorImpl<MDNode *> &DistinctWorklist,
ValueToValueMapTy &VM, RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(!Node.isUniqued() && "Expected temporary or distinct node");
const bool IsDistinct = Node.isDistinct();
bool AnyChanged = false;
for (unsigned I = 0, E = Node.getNumOperands(); I != E; ++I) {
Metadata *Old = Node.getOperand(I);
Metadata *New = mapMetadataOp(Old, DistinctWorklist, VM, Flags, TypeMapper,
Materializer);
if (Old != New) {
AnyChanged = true;
Node.replaceOperandWith(I, New);
// Resolve uniquing cycles underneath distinct nodes on the fly so they
// don't infect later operands.
if (IsDistinct)
resolveCycles(New);
}
}
return AnyChanged;
}
示例3: assert
static llvm::MDNode *stripDebugLocFromLoopID(llvm::MDNode *N) {
assert(N->op_begin() != N->op_end() && "Missing self reference?");
// if there is no debug location, we do not have to rewrite this MDNode.
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
return isa<DILocation>(Op.get());
}))
return N;
// If there is only the debug location without any actual loop metadata, we
// can remove the metadata.
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
return !isa<DILocation>(Op.get());
}))
return nullptr;
SmallVector<Metadata *, 4> Args;
// Reserve operand 0 for loop id self reference.
auto TempNode = MDNode::getTemporary(N->getContext(), None);
Args.push_back(TempNode.get());
// Add all non-debug location operands back.
for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) {
if (!isa<DILocation>(*Op))
Args.push_back(*Op);
}
// Set the first operand to itself.
MDNode *LoopID = MDNode::get(N->getContext(), Args);
LoopID->replaceOperandWith(0, LoopID);
return LoopID;
}
示例4: SetLoopAlreadyUnrolled
// Remove existing unroll metadata and add unroll disable metadata to
// indicate the loop has already been unrolled. This prevents a loop
// from being unrolled more than is directed by a pragma if the loop
// unrolling pass is run more than once (which it generally is).
static void SetLoopAlreadyUnrolled(Loop *L) {
MDNode *LoopID = L->getLoopID();
if (!LoopID) return;
// First remove any existing loop unrolling metadata.
SmallVector<Metadata *, 4> MDs;
// Reserve first location for self reference to the LoopID metadata node.
MDs.push_back(nullptr);
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
bool IsUnrollMetadata = false;
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
if (MD) {
const MDString *S = dyn_cast<MDString>(MD->getOperand(0));
IsUnrollMetadata = S && S->getString().startswith("llvm.loop.unroll.");
}
if (!IsUnrollMetadata)
MDs.push_back(LoopID->getOperand(i));
}
// Add unroll(disable) metadata to disable future unrolling.
LLVMContext &Context = L->getHeader()->getContext();
SmallVector<Metadata *, 1> DisableOperands;
DisableOperands.push_back(MDString::get(Context, "llvm.loop.unroll.disable"));
MDNode *DisableNode = MDNode::get(Context, DisableOperands);
MDs.push_back(DisableNode);
MDNode *NewLoopID = MDNode::get(Context, MDs);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);
L->setLoopID(NewLoopID);
}
示例5: replaceFunctionField
void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
if (!DbgNode)
return;
if (Elt < DbgNode->getNumOperands()) {
MDNode *Node = const_cast<MDNode *>(DbgNode);
Node->replaceOperandWith(Elt, F ? ConstantAsMetadata::get(F) : nullptr);
}
}
示例6: replaceFunctionField
void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
if (DbgNode == 0)
return;
if (Elt < DbgNode->getNumOperands()) {
MDNode *Node = const_cast<MDNode*>(DbgNode);
Node->replaceOperandWith(Elt, F);
}
}
示例7: remapOperands
void MDNodeMapper::remapOperands(MDNode &N, OperandMapper mapOperand) {
assert(!N.isUniqued() && "Expected distinct or temporary nodes");
for (unsigned I = 0, E = N.getNumOperands(); I != E; ++I) {
Metadata *Old = N.getOperand(I);
Metadata *New = mapOperand(Old);
if (Old != New)
N.replaceOperandWith(I, New);
}
}
示例8: assert
static MDNode *createMetadata(LLVMContext &Ctx, const LoopAttributes &Attrs) {
if (!Attrs.IsParallel && Attrs.VectorizerWidth == 0 &&
Attrs.VectorizerUnroll == 0 &&
Attrs.VectorizerEnable == LoopAttributes::VecUnspecified)
return nullptr;
SmallVector<Value *, 4> Args;
// Reserve operand 0 for loop id self reference.
MDNode *TempNode = MDNode::getTemporary(Ctx, None);
Args.push_back(TempNode);
// Setting vectorizer.width
if (Attrs.VectorizerWidth > 0) {
Value *Vals[] = { MDString::get(Ctx, "llvm.loop.vectorize.width"),
ConstantInt::get(Type::getInt32Ty(Ctx),
Attrs.VectorizerWidth) };
Args.push_back(MDNode::get(Ctx, Vals));
}
// Setting vectorizer.unroll
if (Attrs.VectorizerUnroll > 0) {
Value *Vals[] = { MDString::get(Ctx, "llvm.loop.interleave.count"),
ConstantInt::get(Type::getInt32Ty(Ctx),
Attrs.VectorizerUnroll) };
Args.push_back(MDNode::get(Ctx, Vals));
}
// Setting vectorizer.enable
if (Attrs.VectorizerEnable != LoopAttributes::VecUnspecified) {
Value *Vals[] = { MDString::get(Ctx, "llvm.loop.vectorize.enable"),
ConstantInt::get(Type::getInt1Ty(Ctx),
(Attrs.VectorizerEnable ==
LoopAttributes::VecEnable)) };
Args.push_back(MDNode::get(Ctx, Vals));
}
MDNode *LoopID = MDNode::get(Ctx, Args);
assert(LoopID->use_empty() && "LoopID should not be used");
// Set the first operand to itself.
LoopID->replaceOperandWith(0, LoopID);
MDNode::deleteTemporary(TempNode);
return LoopID;
}
示例9: remapOperands
void MDNodeMapper::remapOperands(const Data &D, MDNode &N) {
for (unsigned I = 0, E = N.getNumOperands(); I != E; ++I) {
Metadata *Old = N.getOperand(I);
Metadata *New;
if (Optional<Metadata *> MappedOp = getMappedOp(Old)){
New = *MappedOp;
} else {
assert(!N.isDistinct() &&
"Expected all nodes to be pre-mapped for distinct operands");
MDNode &OldN = *cast<MDNode>(Old);
assert(!OldN.isDistinct() && "Expected distinct nodes to be pre-mapped");
New = &getFwdReference(D, OldN);
}
if (Old != New)
N.replaceOperandWith(I, New);
}
}
示例10:
/// @brief Get a self referencing id metadata node.
///
/// The MDNode looks like this (if arg0/arg1 are not null):
///
/// '!n = metadata !{metadata !n, arg0, arg1}'
///
/// @return The self referencing id metadata node.
static MDNode *getID(LLVMContext &Ctx, Metadata *arg0 = nullptr,
Metadata *arg1 = nullptr) {
MDNode *ID;
SmallVector<Metadata *, 3> Args;
// Use a temporary node to safely create a unique pointer for the first arg.
auto TempNode = MDNode::getTemporary(Ctx, None);
// Reserve operand 0 for loop id self reference.
Args.push_back(TempNode.get());
if (arg0)
Args.push_back(arg0);
if (arg1)
Args.push_back(arg1);
ID = MDNode::get(Ctx, Args);
ID->replaceOperandWith(0, ID);
return ID;
}
示例11:
static MDNode *createMetadata(LLVMContext &Ctx, const LoopAttributes &Attrs) {
if (!Attrs.IsParallel && Attrs.VectorizeWidth == 0 &&
Attrs.InterleaveCount == 0 &&
Attrs.VectorizeEnable == LoopAttributes::Unspecified)
return nullptr;
SmallVector<Metadata *, 4> Args;
// Reserve operand 0 for loop id self reference.
auto TempNode = MDNode::getTemporary(Ctx, None);
Args.push_back(TempNode.get());
// Setting vectorize.width
if (Attrs.VectorizeWidth > 0) {
Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.vectorize.width"),
ConstantAsMetadata::get(ConstantInt::get(
Type::getInt32Ty(Ctx), Attrs.VectorizeWidth))};
Args.push_back(MDNode::get(Ctx, Vals));
}
// Setting interleave.count
if (Attrs.InterleaveCount > 0) {
Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.interleave.count"),
ConstantAsMetadata::get(ConstantInt::get(
Type::getInt32Ty(Ctx), Attrs.InterleaveCount))};
Args.push_back(MDNode::get(Ctx, Vals));
}
// Setting vectorize.enable
if (Attrs.VectorizeEnable != LoopAttributes::Unspecified) {
Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
ConstantAsMetadata::get(ConstantInt::get(
Type::getInt1Ty(Ctx), (Attrs.VectorizeEnable ==
LoopAttributes::Enable)))};
Args.push_back(MDNode::get(Ctx, Vals));
}
// Set the first operand to itself.
MDNode *LoopID = MDNode::get(Ctx, Args);
LoopID->replaceOperandWith(0, LoopID);
return LoopID;
}
示例12: addStringMetadataToLoop
/// \brief Set input string into loop metadata by keeping other values intact.
void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
unsigned V) {
SmallVector<Metadata *, 4> MDs(1);
// If the loop already has metadata, retain it.
MDNode *LoopID = TheLoop->getLoopID();
if (LoopID) {
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
MDNode *Node = cast<MDNode>(LoopID->getOperand(i));
MDs.push_back(Node);
}
}
// Add new metadata.
MDs.push_back(createStringMetadata(TheLoop, MDString, V));
// Replace current metadata node with new one.
LLVMContext &Context = TheLoop->getHeader()->getContext();
MDNode *NewLoopID = MDNode::get(Context, MDs);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);
TheLoop->setLoopID(NewLoopID);
}
示例13: remapOperands
/// Remap the operands of an MDNode.
static bool remapOperands(MDNode &Node,
SmallVectorImpl<MDNode *> &DistinctWorklist,
ValueToValueMapTy &VM, RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(!Node.isUniqued() && "Expected temporary or distinct node");
bool AnyChanged = false;
for (unsigned I = 0, E = Node.getNumOperands(); I != E; ++I) {
Metadata *Old = Node.getOperand(I);
Metadata *New = mapMetadataOp(Old, DistinctWorklist, VM, Flags, TypeMapper,
Materializer);
if (Old != New) {
AnyChanged = true;
Node.replaceOperandWith(I, New);
}
}
return AnyChanged;
}
示例14: Args
MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) {
// To ensure uniqueness the root node is self-referential.
auto Dummy = MDNode::getTemporary(Context, None);
SmallVector<Metadata *, 3> Args(1, Dummy.get());
if (Extra)
Args.push_back(Extra);
if (!Name.empty())
Args.push_back(createString(Name));
MDNode *Root = MDNode::get(Context, Args);
// At this point we have
// !0 = metadata !{} <- dummy
// !1 = metadata !{metadata !0} <- root
// Replace the dummy operand with the root node itself and delete the dummy.
Root->replaceOperandWith(0, Root);
// We now have
// !1 = metadata !{metadata !1} <- self-referential root
return Root;
}
示例15:
MDNode *llvm::makePostTransformationMetadata(LLVMContext &Context,
MDNode *OrigLoopID,
ArrayRef<StringRef> RemovePrefixes,
ArrayRef<MDNode *> AddAttrs) {
// First remove any existing loop metadata related to this transformation.
SmallVector<Metadata *, 4> MDs;
// Reserve first location for self reference to the LoopID metadata node.
TempMDTuple TempNode = MDNode::getTemporary(Context, None);
MDs.push_back(TempNode.get());
// Remove metadata for the transformation that has been applied or that became
// outdated.
if (OrigLoopID) {
for (unsigned i = 1, ie = OrigLoopID->getNumOperands(); i < ie; ++i) {
bool IsVectorMetadata = false;
Metadata *Op = OrigLoopID->getOperand(i);
if (MDNode *MD = dyn_cast<MDNode>(Op)) {
const MDString *S = dyn_cast<MDString>(MD->getOperand(0));
if (S)
IsVectorMetadata =
llvm::any_of(RemovePrefixes, [S](StringRef Prefix) -> bool {
return S->getString().startswith(Prefix);
});
}
if (!IsVectorMetadata)
MDs.push_back(Op);
}
}
// Add metadata to avoid reapplying a transformation, such as
// llvm.loop.unroll.disable and llvm.loop.isvectorized.
MDs.append(AddAttrs.begin(), AddAttrs.end());
MDNode *NewLoopID = MDNode::getDistinct(Context, MDs);
// Replace the temporary node with a self-reference.
NewLoopID->replaceOperandWith(0, NewLoopID);
return NewLoopID;
}