[llvm] [C API] Add blockaddress getters to C API (PR #81382)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 11 03:25:27 PST 2024
================
@@ -136,3 +136,31 @@ int llvm_module_list_globals(void) {
return 0;
}
+
+int llvm_module_list_global_block_address_values(void) {
+ LLVMModuleRef M = llvm_load_module(false, false);
+ LLVMValueRef g;
+
+ g = LLVMGetFirstGlobal(M);
+ while (g) {
+ LLVMValueRef GInit = LLVMGetInitializer(g);
+
+ if (GInit && LLVMIsABlockAddress(GInit)) {
+ const char *GlobalName = LLVMGetValueName(g);
+ LLVMValueRef Func = LLVMGetBlockAddressFunction(GInit);
+ LLVMBasicBlockRef BB = LLVMGetBlockAddressBasicBlock(GInit);
+
+ const char *FuncName = LLVMGetValueName(Func);
+ const char *BBName = LLVMGetBasicBlockName(BB);
+
+ printf("BlockAddress '%s' Func '%s' Basic Block '%s'\n", GlobalName,
+ FuncName, BBName);
+ }
+
+ g = LLVMGetNextGlobal(g);
+ }
+
+ LLVMDisposeModule(M);
+
+ return 0;
+}
----------------
nikic wrote:
You don't have to go through llvm-c-test with IR input, you can also directly add a unit test in https://github.com/llvm/llvm-project/blob/main/llvm/unittests/IR/ConstantsTest.cpp. Basically just call LLVMBlockAddress and then the getter on that and check that the inputs & outputs are the same.
https://github.com/llvm/llvm-project/pull/81382
More information about the llvm-commits
mailing list