]> granicus.if.org Git - llvm/commitdiff
[LLVM-C] Add Bindings to Access an Instruction's DebugLoc
authorRobert Widmann <devteam.codafi@gmail.com>
Tue, 9 Apr 2019 22:27:51 +0000 (22:27 +0000)
committerRobert Widmann <devteam.codafi@gmail.com>
Tue, 9 Apr 2019 22:27:51 +0000 (22:27 +0000)
Summary: Provide direct accessors to supplement LLVMSetInstDebugLocation.  In addition, properly accept and return the NULL location.  The old accessors provided no way to do this, so the current debug location cannot currently be cleared.

Reviewers: whitequark, deadalnix

Reviewed By: whitequark

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60481

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358038 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/DebugInfo.h
lib/IR/DebugInfo.cpp

index 99e977da15e3c4c62a44f790912a58dea33fd1bb..655b80d2796ee0adb5c64aed53f64258033c33d6 100644 (file)
@@ -1192,6 +1192,22 @@ LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func);
  */
 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP);
 
+/**
+ * Get the debug location for the given instruction.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ */
+LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst);
+
+/**
+ * Set the debug location for the given instruction.
+ *
+ * To clear the location metadata of the given instruction, pass NULL to \p Loc.
+ *
+ * @see llvm::Instruction::setDebugLoc()
+ */
+void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
+
 /**
  * Obtain the enumerated type of a Metadata instance.
  *
index a9d91214a802030bd99cc0fa3a5807d9b9b33e4c..ef21b6a555f4ba7304c6ace2438e100a79c0606d 100644 (file)
@@ -1355,6 +1355,17 @@ void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
   unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
 }
 
+LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) {
+  return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
+}
+
+void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
+  if (Loc)
+    unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
+  else
+    unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
+}
+
 LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
   switch(unwrap(Metadata)->getMetadataID()) {
 #define HANDLE_METADATA_LEAF(CLASS) \