本文整理汇总了C++中MDNode类的典型用法代码示例。如果您正苦于以下问题:C++ MDNode类的具体用法?C++ MDNode怎么用?C++ MDNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MDNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
// 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);
if (LoopID) {
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);
}
示例2: getModuleFlagsMetadata
/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
void Module::
getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
const NamedMDNode *ModFlags = getModuleFlagsMetadata();
if (!ModFlags) return;
for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
MDNode *Flag = ModFlags->getOperand(i);
ConstantInt *Behavior = cast<ConstantInt>(Flag->getOperand(0));
MDString *Key = cast<MDString>(Flag->getOperand(1));
Value *Val = Flag->getOperand(2);
Flags.push_back(ModuleFlagEntry(ModFlagBehavior(Behavior->getZExtValue()),
Key, Val));
}
}
示例3: getID
void ScopAnnotator::pushLoop(Loop *L, bool IsParallel) {
ActiveLoops.push_back(L);
if (!IsParallel)
return;
BasicBlock *Header = L->getHeader();
MDNode *Id = getID(Header->getContext());
assert(Id->getOperand(0) == Id && "Expected Id to be a self-reference");
assert(Id->getNumOperands() == 1 && "Unexpected extra operands in Id");
MDNode *Ids = ParallelLoops.empty()
? Id
: MDNode::concatenate(ParallelLoops.back(), Id);
ParallelLoops.push_back(Ids);
}
示例4: assert
bool MDNodeMapper::createPOT(UniquedGraph &G, const MDNode &FirstN) {
assert(G.Info.empty() && "Expected a fresh traversal");
assert(FirstN.isUniqued() && "Expected uniqued node in POT");
// Construct a post-order traversal of the uniqued subgraph under FirstN.
bool AnyChanges = false;
SmallVector<POTWorklistEntry, 16> Worklist;
Worklist.push_back(POTWorklistEntry(const_cast<MDNode &>(FirstN)));
(void)G.Info[&FirstN];
while (!Worklist.empty()) {
// Start or continue the traversal through the this node's operands.
auto &WE = Worklist.back();
if (MDNode *N = visitOperands(G, WE.Op, WE.N->op_end(), WE.HasChanged)) {
// Push a new node to traverse first.
Worklist.push_back(POTWorklistEntry(*N));
continue;
}
// Push the node onto the POT.
assert(WE.N->isUniqued() && "Expected only uniqued nodes");
assert(WE.Op == WE.N->op_end() && "Expected to visit all operands");
auto &D = G.Info[WE.N];
AnyChanges |= D.HasChanged = WE.HasChanged;
D.ID = G.POT.size();
G.POT.push_back(WE.N);
// Pop the node off the worklist.
Worklist.pop_back();
}
return AnyChanges;
}
示例5: assert
void RuntimeHelperFixupPass::FixArrayInit(Function *F)
{
Module *M = F->getParent();
LLVMContext &ctx = F->getContext();
for (auto it = F->use_begin(), end = F->use_end(); it != end; ++it)
{
CallInst *CI = dyn_cast<CallInst>(*it);
assert (CI && "Unknown usage for array init helper");
Instruction *field_runtime_handle = dyn_cast<Instruction>(CI->getArgOperand(1));
assert (field_runtime_handle);
MDNode *md = field_runtime_handle->getMetadata("silk_runtime_field_handle");
assert (md);
ConstantInt *handle = dyn_cast<ConstantInt>(md->getOperand(0));
assert(handle);
auto vm_field = reinterpret_cast<VMField*>(handle->getValue().getLimitedValue());
auto field_map = vm_field->field_mapping();
auto vm_named_class = dynamic_cast<VMNamedClass*>(vm_field->type());
auto size = vm_named_class->type_def()->class_size();
raw_istream is(field_map.start(), size);
std::vector<uint8_t> buf;
buf.resize(size);
is.read((char*)buf.data(), size);
Constant *predefined_value = ConstantDataArray::get(ctx, buf);
auto GV = new GlobalVariable(*M, predefined_value->getType(),
true, GlobalValue::InternalLinkage,
predefined_value, ".initdata");
Value *array_ptr = CI->getArgOperand(0);
IRBuilder<> builder(CI);
auto intrinsic_array_base = intrinsic_->array_base_pointer();
auto array_ptr_casted = builder.CreateBitCast(array_ptr, builder.getInt8PtrTy());
auto array_base_ptr = builder.CreateCall(intrinsic_array_base, array_ptr_casted);
builder.CreateMemCpy(array_base_ptr, GV, ConstantInt::get(Type::getInt64Ty(ctx), size), 0);
CI->eraseFromParent();
}
}
示例6: 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);
}
}
示例7: getOptionalBoolLoopAttribute
static Optional<bool> getOptionalBoolLoopAttribute(const Loop *TheLoop,
StringRef Name) {
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
if (!MD)
return None;
switch (MD->getNumOperands()) {
case 1:
// When the value is absent it is interpreted as 'attribute set'.
return true;
case 2:
if (ConstantInt *IntMD =
mdconst::extract_or_null<ConstantInt>(MD->getOperand(1).get()))
return IntMD->getZExtValue();
return true;
}
llvm_unreachable("unexpected number of options");
}
示例8:
static const MCSymbolELF *getAssociatedSymbol(const GlobalObject *GO,
const TargetMachine &TM) {
MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
if (!MD)
return nullptr;
const MDOperand &Op = MD->getOperand(0);
if (!Op.get())
return nullptr;
auto *VM = dyn_cast<ValueAsMetadata>(Op);
if (!VM)
report_fatal_error("MD_associated operand is not ValueAsMetadata");
GlobalObject *OtherGO = dyn_cast<GlobalObject>(VM->getValue());
return OtherGO ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGO)) : nullptr;
}
示例9: 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;
}
示例10: assert
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);
}
}
示例11: isTBAAVtableAccess
bool MDNode::isTBAAVtableAccess() const {
if (!isStructPathTBAA(this)) {
if (getNumOperands() < 1) return false;
if (MDString *Tag1 = dyn_cast<MDString>(getOperand(0))) {
if (Tag1->getString() == "vtable pointer") return true;
}
return false;
}
// For struct-path aware TBAA, we use the access type of the tag.
if (getNumOperands() < 2) return false;
MDNode *Tag = cast_or_null<MDNode>(getOperand(1));
if (!Tag) return false;
if (MDString *Tag1 = dyn_cast<MDString>(Tag->getOperand(0))) {
if (Tag1->getString() == "vtable pointer") return true;
}
return false;
}
示例12: assert
/// \brief Map a distinct MDNode.
///
/// Distinct nodes are not uniqued, so they must always recreated.
static Metadata *mapDistinctNode(const MDNode *Node,
SmallVectorImpl<MDNode *> &Cycles,
ValueToValueMapTy &VM, RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(Node->isDistinct() && "Expected distinct node");
MDNode *NewMD = MDNode::replaceWithDistinct(Node->clone());
remap(Node, NewMD, Cycles, VM, Flags, TypeMapper, Materializer);
// Track any cycles beneath this node.
for (Metadata *Op : NewMD->operands())
if (auto *Node = dyn_cast_or_null<MDNode>(Op))
if (!Node->isResolved())
Cycles.push_back(Node);
return NewMD;
}
示例13: assert
/// createObjectPointerType - Create a new type with both the object pointer
/// and artificial flags set.
DIType DIBuilder::createObjectPointerType(DIType Ty) {
if (Ty.isObjectPointer())
return Ty;
SmallVector<Value *, 9> Elts;
MDNode *N = Ty;
assert (N && "Unexpected input DIType!");
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
Elts.push_back(N->getOperand(i));
unsigned CurFlags = Ty.getFlags();
CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
// Flags are stored at this slot.
Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
return DIType(MDNode::get(VMContext, Elts));
}
示例14:
/// @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;
}
示例15: lowerJuliaArrayArguments
std::vector<Type*> lowerJuliaArrayArguments(Function *OldFunc) {
Module* M = OldFunc->getParent();
LLVMContext &context = M->getContext();
NamedMDNode* JuliaArgs = M->getOrInsertNamedMetadata("julia.args");
MDNode *node = JuliaArgs->getOperand(0);
int operand = 0;
std::vector<Type*> ArgTypes;
for (Function::const_arg_iterator I = OldFunc->arg_begin(), E = OldFunc->arg_end(); I != E; ++I) {
Type* argType = I->getType();
if (is_jl_array_type(argType)) {
// Gets the type from custom metadata
Value *value = node->getOperand(operand);
if (MDString* mdstring = dyn_cast<MDString>(value)) {
if (Type* type = extractType(context, mdstring->getString())) {
ArgTypes.push_back(type);
} else {
errs() << "Could not extract type: ";
mdstring->print(errs());
errs() << "\n";
exit(1);
}
} else {
errs() << "Could not extract type: ";
value->print(errs());
errs() << "\n";
exit(1);
}
} else {
ArgTypes.push_back(I->getType());
}
operand++;
}
return ArgTypes;
}