Skip to content

Commit 7cfc9a3

Browse files
authored
[llvm-c] Add getters for LLVMContextRef for various types (#99087)
Small PR to add additional getters for LLVMContextRef in the C API.
1 parent 39e3085 commit 7cfc9a3

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ Changes to the C API
157157
* ``LLVMGetNamedFunctionWithLength``
158158
* ``LLVMGetNamedGlobalWithLength``
159159

160+
* The following functions are added to access the ``LLVMContextRef`` associated
161+
with ``LLVMValueRef`` and ``LLVMBuilderRef`` objects:
162+
163+
* ``LLVMGetValueContext``
164+
* ``LLVMGetBuilderContext``
165+
160166
* The new pass manager can now be invoked with a custom alias analysis pipeline, using
161167
the ``LLVMPassBuilderOptionsSetAAPipeline`` function.
162168

llvm/include/llvm-c/Core.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,13 @@ void LLVMDumpValue(LLVMValueRef Val);
19731973
*/
19741974
char *LLVMPrintValueToString(LLVMValueRef Val);
19751975

1976+
/**
1977+
* Obtain the context to which this value is associated.
1978+
*
1979+
* @see llvm::Value::getContext()
1980+
*/
1981+
LLVMContextRef LLVMGetValueContext(LLVMValueRef Val);
1982+
19761983
/**
19771984
* Return a string representation of the DbgRecord. Use
19781985
* LLVMDisposeMessage to free the string.
@@ -4160,6 +4167,13 @@ LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
41604167
void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
41614168
LLVMMetadataRef FPMathTag);
41624169

4170+
/**
4171+
* Obtain the context to which this builder is associated.
4172+
*
4173+
* @see llvm::IRBuilder::getContext()
4174+
*/
4175+
LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder);
4176+
41634177
/**
41644178
* Deprecated: Passing the NULL location will crash.
41654179
* Use LLVMGetCurrentDebugLocation2 instead.

llvm/lib/IR/Core.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,10 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
10441044
return strdup(buf.c_str());
10451045
}
10461046

1047+
LLVMContextRef LLVMGetValueContext(LLVMValueRef Val) {
1048+
return wrap(&unwrap(Val)->getContext());
1049+
}
1050+
10471051
char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record) {
10481052
std::string buf;
10491053
raw_string_ostream os(buf);
@@ -3329,6 +3333,10 @@ void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
33293333
: nullptr);
33303334
}
33313335

3336+
LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder) {
3337+
return wrap(&unwrap(Builder)->getContext());
3338+
}
3339+
33323340
LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder) {
33333341
return wrap(unwrap(Builder)->getDefaultFPMathTag());
33343342
}

0 commit comments

Comments
 (0)