[llvm] [llvm-c] Add getters for LLVMContextRef for various types (PR #99087)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 12:34:55 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Bogdan-Alexandru Geană (abgeana)
<details>
<summary>Changes</summary>
Small PR to add additional getters for LLVMContextRef in the C API.
---
Full diff: https://github.com/llvm/llvm-project/pull/99087.diff
2 Files Affected:
- (modified) llvm/include/llvm-c/Core.h (+21)
- (modified) llvm/lib/IR/Core.cpp (+12)
``````````diff
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 9867db4839fe1..18e8cf9de41c8 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -1918,6 +1918,13 @@ void LLVMDumpValue(LLVMValueRef Val);
*/
char *LLVMPrintValueToString(LLVMValueRef Val);
+/**
+ * Obtain the context to which this value is associated.
+ *
+ * @see llvm::Value::getContext()
+ */
+LLVMContextRef LLVMGetValueContext(LLVMValueRef Val);
+
/**
* Return a string representation of the DbgRecord. Use
* LLVMDisposeMessage to free the string.
@@ -3434,6 +3441,13 @@ void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
*/
void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
+/**
+ * Obtain the context to which this basic block is associated.
+ *
+ * @see llvm::Module::getContext()
+ */
+LLVMContextRef LLVMGetBasicBlockContext(LLVMBasicBlockRef BB);
+
/**
* Obtain the first instruction in a basic block.
*
@@ -4070,6 +4084,13 @@ LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
LLVMMetadataRef FPMathTag);
+/**
+ * Obtain the context to which this builder is associated.
+ *
+ * @see llvm::IRBuilder::getContext()
+ */
+LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder);
+
/**
* Deprecated: Passing the NULL location will crash.
* Use LLVMGetCurrentDebugLocation2 instead.
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 9ba7873106043..044e0c5adf136 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1036,6 +1036,10 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
return strdup(buf.c_str());
}
+LLVMContextRef LLVMGetValueContext(LLVMValueRef Val) {
+ return wrap(&unwrap(Val)->getContext());
+}
+
char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record) {
std::string buf;
raw_string_ostream os(buf);
@@ -2823,6 +2827,10 @@ void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
unwrap(BB)->moveAfter(unwrap(MovePos));
}
+LLVMContextRef LLVMGetBasicBlockContext(LLVMBasicBlockRef BB) {
+ return wrap(&unwrap(BB)->getContext());
+}
+
/*--.. Operations on instructions ..........................................--*/
LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
@@ -3256,6 +3264,10 @@ void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
: nullptr);
}
+LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder) {
+ return wrap(&unwrap(Builder)->getContext());
+}
+
LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder) {
return wrap(unwrap(Builder)->getDefaultFPMathTag());
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/99087
More information about the llvm-commits
mailing list