通过 C API 获取 llvm CallInst 的属性

get llvm CallInst's attributes via C API

如何通过 C API(版本 3.9)获取 CallInst 的属性(包括 return 值、参数、函数)?

我可以为 Function 属性找到一些 api 但找不到 CallInst,此外,对于给定的函数:

declare noalias i8* @malloc(i64) #1

LLVMGetFunctionAttr returns 32,而 noalias 属性应为 64

获取调用函数:getCalledFunction

传递给被调用函数的参数:getAttributes

Return Value:可以使用调用指令对象作为调用的值。

对于函数属性(未测试):

LLVMValueRef YourFunction = LLVMGetCalledValue(F);
// Index is your attribute's number, e.g. first one is 0
// Length is how many attributes are there in the #Index list
unsigned Length = LLVMGetAttributeCountAtIndex(YouFunction, Index));
LLVMAttributeRef *Array = malloc(sizeof(LLVMAttributeRef) * Length);
// Save list of attributes of #Index attr of function
LLVMGetAttributesAtIndex(YourFunction, Index, Array);
// So, for `declare noalias i8* @malloc(i64) !{ nounwind }`
// Array should be [nounwind] (array of one element)