MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
}
-LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
- unsigned Count) {
- return wrap(MDTuple::getTemporary(*unwrap(C),
- ArrayRef<Metadata *>(unwrap(MDs), Count))
- .release());
-}
-
void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
LLVMMetadataRef Val) {
NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
}
-void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
- auto *Node = unwrap<MDNode>(MD);
- Node->replaceAllUsesWith(unwrap<Metadata>(New));
- MDNode::deleteTemporary(Node);
-}
-
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
unsigned Col, LLVMMetadataRef Scope,
LLVMMetadataRef InlinedAt) {
LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen);
LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
unsigned Count);
-LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
- unsigned Count);
void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
LLVMMetadataRef Val);
void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD);
-void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New);
-
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
unsigned Col, LLVMMetadataRef Scope,
LLVMMetadataRef InlinedAt);
}
return 0
}
+
+//-------------------------------------------------------------------------
+// llvm.Metadata
+//-------------------------------------------------------------------------
+
+func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) {
+ ptr, nvals := llvmMetadataRefs(mds)
+ md.C = C.LLVMTemporaryMDNode(c.C, ptr, C.size_t(nvals))
+ return
+}
+
+func (md Metadata) ReplaceAllUsesWith(new Metadata) {
+ C.LLVMMetadataReplaceAllUsesWith(md.C, new.C)
+}
md.C = C.LLVMMDNode2(c.C, ptr, nvals)
return
}
-func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) {
- ptr, nvals := llvmMetadataRefs(mds)
- md.C = C.LLVMTemporaryMDNode(c.C, ptr, nvals)
- return
-}
func (v Value) ConstantAsMetadata() (md Metadata) {
md.C = C.LLVMConstantAsMetadata(v.C)
return
// the module provider.
// See llvm::PassManagerBase::~PassManagerBase.
func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }
-
-//-------------------------------------------------------------------------
-// llvm.Metadata
-//-------------------------------------------------------------------------
-
-func (md Metadata) ReplaceAllUsesWith(new Metadata) {
- C.LLVMMetadataReplaceAllUsesWith(md.C, new.C)
-}
LLVMMetadataRef Expr,
LLVMMetadataRef Decl,
uint32_t AlignInBits);
+/**
+ * Create a new temporary \c MDNode. Suitable for use in constructing cyclic
+ * \c MDNode structures. A temporary \c MDNode is not uniqued, may be RAUW'd,
+ * and must be manually deleted with \c LLVMDisposeTemporaryMDNode.
+ * \param Ctx The context in which to construct the temporary node.
+ * \param Data The metadata elements.
+ * \param NumElements Number of metadata elements.
+ */
+LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
+ size_t NumElements);
+
+/**
+ * Deallocate a temporary node.
+ *
+ * Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
+ * references will be reset.
+ * \param TempNode The temporary metadata node.
+ */
+void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode);
+
+/**
+ * Replace all uses of temporary metadata.
+ * \param TempTargetMetadata The temporary metadata node.
+ * \param Replacement The replacement metadata node.
+ */
+void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata,
+ LLVMMetadataRef Replacement);
/**
* Create a new descriptor for the specified global variable that is temporary
unwrapDI<MDNode>(Decl), AlignInBits));
}
+LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
+ size_t Count) {
+ return wrap(
+ MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
+}
+
+void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) {
+ MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
+}
+
+void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata,
+ LLVMMetadataRef Replacement) {
+ auto *Node = unwrapDI<MDNode>(TargetMetadata);
+ Node->replaceAllUsesWith(unwrap<Metadata>(Replacement));
+ MDNode::deleteTemporary(Node);
+}
+
LLVMMetadataRef
LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder,
LLVMMetadataRef Scope,
LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty, VectorTy};
LLVMMetadataRef FunctionTy =
LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 3, 0);
+
+ LLVMMetadataRef ReplaceableFunctionMetadata =
+ LLVMDIBuilderCreateReplaceableCompositeType(DIB, 0x15, "foo", 3,
+ File, File, 42,
+ 0, 0, 0,
+ LLVMDIFlagFwdDecl,
+ "", 0);
+
+ LLVMMetadataRef FooParamLocation =
+ LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
+ ReplaceableFunctionMetadata, NULL);
LLVMMetadataRef FunctionMetadata =
LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
File, 42, FunctionTy, true, true,
42, 0, false);
+ LLVMMetadataReplaceAllUsesWith(ReplaceableFunctionMetadata, FunctionMetadata);
- LLVMMetadataRef FooParamLocation =
- LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
- FunctionMetadata, NULL);
LLVMMetadataRef FooParamExpression =
LLVMDIBuilderCreateExpression(DIB, NULL, 0);
LLVMMetadataRef FooParamVar1 =