Skip to content

[llvm-c] Add getters for LLVMContextRef for various types #99087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ Changes to the C API
* ``LLVMGetNamedFunctionWithLength``
* ``LLVMGetNamedGlobalWithLength``

* The following functions are added to access the ``LLVMContextRef`` associated
with ``LLVMValueRef`` and ``LLVMBuilderRef`` objects:

* ``LLVMGetValueContext``
* ``LLVMGetBuilderContext``

* The new pass manager can now be invoked with a custom alias analysis pipeline, using
the ``LLVMPassBuilderOptionsSetAAPipeline`` function.

Expand Down
14 changes: 14 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,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.
Expand Down Expand Up @@ -4160,6 +4167,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.
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,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);
Expand Down Expand Up @@ -3329,6 +3333,10 @@ void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
: nullptr);
}

LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder) {
return wrap(&unwrap(Builder)->getContext());
}

LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder) {
return wrap(unwrap(Builder)->getDefaultFPMathTag());
}
Expand Down
Loading