Skip to content

Commit 1cc19d8

Browse files
committed
[C API] Add accessors for function prefix and prologue data
A test is added to echo.ll, and the echo.cpp part of llvm-c-test is updated to clone a function's prefix and prologue
1 parent dc94eb5 commit 1cc19d8

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ Changes to the C API
125125
* Added ``LLVMGetBlockAddressFunction`` and ``LLVMGetBlockAddressBasicBlock``
126126
functions for accessing the values in a blockaddress constant.
127127

128+
* Added the following functions for accessing a function's prefix data:
129+
130+
* ``LLVMHasPrefixData``
131+
* ``LLVMGetPrefixData``
132+
* ``LLVMSetPrefixData``
133+
134+
* Added the following functions for accessing a function's prologue data:
135+
136+
* ``LLVMHasPrologueData``
137+
* ``LLVMGetPrologueData``
138+
* ``LLVMSetPrologueData``
139+
128140
Changes to the CodeGen infrastructure
129141
-------------------------------------
130142

llvm/include/llvm-c/Core.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,44 @@ const char *LLVMGetGC(LLVMValueRef Fn);
27192719
*/
27202720
void LLVMSetGC(LLVMValueRef Fn, const char *Name);
27212721

2722+
/**
2723+
* Gets the prefix data associated with a function. Only valid on functions, and
2724+
* only if LLVMHasPrefixData returns true.
2725+
* See https://llvm.org/docs/LangRef.html#prefix-data
2726+
*/
2727+
LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn);
2728+
2729+
/**
2730+
* Check if a given function has prefix data. Only valid on functions.
2731+
* See https://llvm.org/docs/LangRef.html#prefix-data
2732+
*/
2733+
LLVMBool LLVMHasPrefixData(LLVMValueRef Fn);
2734+
2735+
/**
2736+
* Sets the prefix data for the function. Only valid on functions.
2737+
* See https://llvm.org/docs/LangRef.html#prefix-data
2738+
*/
2739+
void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData);
2740+
2741+
/**
2742+
* Gets the prologue data associated with a function. Only valid on functions,
2743+
* and only if LLVMHasPrologueData returns true.
2744+
* See https://llvm.org/docs/LangRef.html#prologue-data
2745+
*/
2746+
LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn);
2747+
2748+
/**
2749+
* Check if a given function has prologue data. Only valid on functions.
2750+
* See https://llvm.org/docs/LangRef.html#prologue-data
2751+
*/
2752+
LLVMBool LLVMHasPrologueData(LLVMValueRef Fn);
2753+
2754+
/**
2755+
* Sets the prologue data for the function. Only valid on functions.
2756+
* See https://llvm.org/docs/LangRef.html#prologue-data
2757+
*/
2758+
void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData);
2759+
27222760
/**
27232761
* Add an attribute to a function.
27242762
*

llvm/lib/IR/Core.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,38 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
24052405
F->clearGC();
24062406
}
24072407

2408+
LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn) {
2409+
Function *F = unwrap<Function>(Fn);
2410+
return wrap(F->getPrefixData());
2411+
}
2412+
2413+
LLVMBool LLVMHasPrefixData(LLVMValueRef Fn) {
2414+
Function *F = unwrap<Function>(Fn);
2415+
return F->hasPrefixData();
2416+
}
2417+
2418+
void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData) {
2419+
Function *F = unwrap<Function>(Fn);
2420+
Constant *prefix = unwrap<Constant>(prefixData);
2421+
F->setPrefixData(prefix);
2422+
}
2423+
2424+
LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn) {
2425+
Function *F = unwrap<Function>(Fn);
2426+
return wrap(F->getPrologueData());
2427+
}
2428+
2429+
LLVMBool LLVMHasPrologueData(LLVMValueRef Fn) {
2430+
Function *F = unwrap<Function>(Fn);
2431+
return F->hasPrologueData();
2432+
}
2433+
2434+
void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData) {
2435+
Function *F = unwrap<Function>(Fn);
2436+
Constant *prologue = unwrap<Constant>(prologueData);
2437+
F->setPrologueData(prologue);
2438+
}
2439+
24082440
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
24092441
LLVMAttributeRef A) {
24102442
unwrap<Function>(F)->addAttributeAtIndex(Idx, unwrap(A));

llvm/test/Bindings/llvm-c/echo.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ define void @test_fast_math_flags_call_outer(float %a) {
334334
ret void
335335
}
336336

337+
define void @test_func_prefix_data_01() prefix i32 123 {
338+
ret void
339+
}
340+
341+
define void @test_func_prefix_data_02() prefix i64 2000 {
342+
ret void
343+
}
344+
345+
%func_prolog_struct = type <{ i8, i8, ptr }>
346+
347+
define void @test_func_prologue_data_01() prologue %func_prolog_struct <{ i8 235, i8 8, ptr zeroinitializer}> {
348+
ret void
349+
}
350+
337351
!llvm.dbg.cu = !{!0, !2}
338352
!llvm.module.flags = !{!3}
339353

llvm/tools/llvm-c-test/echo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,14 @@ static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) {
13971397
}
13981398
LLVMDisposeValueMetadataEntries(AllMetadata);
13991399

1400+
// Copy any prefix data that may be on the function
1401+
if (LLVMHasPrefixData(Cur))
1402+
LLVMSetPrefixData(Fun, LLVMGetPrefixData(Cur));
1403+
1404+
// Copy any prologue data that may be on the function
1405+
if (LLVMHasPrologueData(Cur))
1406+
LLVMSetPrologueData(Fun, LLVMGetPrologueData(Cur));
1407+
14001408
FunCloner FC(Cur, Fun);
14011409
FC.CloneBBs(Cur);
14021410

0 commit comments

Comments
 (0)