获取调用中位转换中函数的参数,llvm

获取调用中位转换中函数的参数,llvm,llvm,llvm-gcc,Llvm,Llvm Gcc,我是llvm的新手,很难深入了解以下IR行: %call2 = call float bitcast (float (float, i32*)* @function to float (float, i32 addrspace(1)*)*)(float %11, i32 addrspace(1)* %arrayidx) 我需要从这一行中提取函数的参数类型(即,(float%11,i32 addrspace(1)*%arrayidx)) 我尝试了以下方法,并与ConstExpr玩了一点arrou

我是llvm的新手,很难深入了解以下IR行:

%call2 = call float bitcast (float (float, i32*)* @function to float (float, i32 addrspace(1)*)*)(float %11, i32 addrspace(1)* %arrayidx)
我需要从这一行中提取函数的参数类型(即,(float%11,i32 addrspace(1)*%arrayidx))

我尝试了以下方法,并与ConstExpr玩了一点arround,但无法提取addrspace(1)

for(Function::iterator block=F.begin(),blockEnd=F.end();block!=blockEnd;++block){
对于(基本块::迭代器inst=block->begin(),instEnd=block->end();inst!=instEnd;++inst){
如果(CallInst*call=dyn_cast(inst)){
函数*calledFunction=call->getCalledFunction();
如果(calledFunction==NULL){//被调用函数被包装在位广播中
Value*v=call->getCalledValue();
calledFunction=dyn_cast(v->stripPointerCasts());
FunctionType*ft=calledFunction->getFunctionType();//这给了我类型“from”(不带addrspace(1)的参数)
对于(函数::arg_迭代器arg=calledFunction->arg_begin(),marg_end=calledFunction->arg_end();arg!=marg_end;arg++){
键入*argTy=arg->getType();
if(指针类型*ptrTy=dyn_cast(argTy)){
如果(ptrTy->getAddressSpace()!=0)
...
}
}
}
}
}
}
上面的代码给出了类型(float,i32*)和not(float,i32 addrspace(1)*)

有什么帮助吗?

llvm ir

%call2 = call float bitcast (float (float, i32*)* @function to float (float, i32 addrspace(1)*)*)(float %11, i32 addrspace(1)* %arrayidx)
正在将函数类型
float(float,i32*)
转换为
float(float,i32 addrspace(1)*)
,并使用参数
(%11,%arrayidx)
调用它

如果需要参数类型,可以使用
callInst::getArgOperand
检查它,以获取调用指令本身中的参数

for (Function::iterator block = F.begin(), blockEnd = F.end(); block != blockEnd; ++block) {
    for (BasicBlock::iterator inst = block->begin(), instEnd = block->end(); inst != instEnd; ++inst) {
        if (CallInst *call = dyn_cast<CallInst>(inst)) {
                Value *val11 = call->getArgOperand(0);
                Value *valarrayIdx = call->getArgOperand(1);

                Type *val11ty = val11->getType(); // this should be of float
                Type *valarrayIdx = valarrayIdx->getType(); // this should be of i32 address(1)*
            }
        }
    }
for(Function::iterator block=F.begin(),blockEnd=F.end();block!=blockEnd;++block){
对于(基本块::迭代器inst=block->begin(),instEnd=block->end();inst!=instEnd;++inst){
如果(CallInst*call=dyn_cast(inst)){
Value*val11=call->getArgOperand(0);
Value*valarrayIdx=call->getArgOperand(1);
键入*val11ty=val11->getType();//这应该是浮点型
键入*valarrayIdx=valarrayIdx->getType();//这应该是i32地址(1)*
}
}
}
CallInst::getCalledFunction
将为您提供该函数


要了解更多信息,您可以浏览一下

太好了!现在它有意义了。谢谢。您还知道如何获取返回参数吗?(%call2在本例中)我在@Shervin中找不到与callinst的return参数相关的任何内容。
callinst
本身是一个与返回值相对应的
值。
for (Function::iterator block = F.begin(), blockEnd = F.end(); block != blockEnd; ++block) {
    for (BasicBlock::iterator inst = block->begin(), instEnd = block->end(); inst != instEnd; ++inst) {
        if (CallInst *call = dyn_cast<CallInst>(inst)) {
                Value *val11 = call->getArgOperand(0);
                Value *valarrayIdx = call->getArgOperand(1);

                Type *val11ty = val11->getType(); // this should be of float
                Type *valarrayIdx = valarrayIdx->getType(); // this should be of i32 address(1)*
            }
        }
    }