[llvm] [llvm-c] Add getters for LLVMContextRef for various types (PR #99087)
Bogdan-Alexandru Geană via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 12:34:06 PDT 2024
https://github.com/abgeana created https://github.com/llvm/llvm-project/pull/99087
Small PR to add additional getters for LLVMContextRef in the C API.
>From 1f0f56941859a3b83cba81d0cda70ed343efa569 Mon Sep 17 00:00:00 2001
From: Alexandru Geana <ab at geana.io>
Date: Tue, 16 Jul 2024 21:27:20 +0200
Subject: [PATCH] [llvm-c] Add getters for LLVMContextRef for various types
---
llvm/include/llvm-c/Core.h | 21 +++++++++++++++++++++
llvm/lib/IR/Core.cpp | 12 ++++++++++++
2 files changed, 33 insertions(+)
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());
}
More information about the llvm-commits
mailing list