Ahmad Nouralizadeh Khorrami via llvm-dev
2018-Aug-16 11:15 UTC
[llvm-dev] Convert Function Pointer Call to Function Call at the IR Level
Hi, I want to convert a function pointer call in the IR of MPlayer to a function call. For example, I have the following line: ... %10 = tail call i32 %7(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7, !dbg !863222 ... I want to set the target which is stored in %7 to a real function called "demux_lavf_control()" with the following definition: ... define internal i32 @demux_lavf_control(%struct.demuxer.2657* nocapture readonly, i32, i8* nocapture) #0 !dbg !963916 { ... I wrote a function pass and found the mentioned function pointer call (here, stored in "CallInstr") and set the call target as follows: ... Module *theModule = F.getParent(); Function *targetFunc = theModule->getFunction("demux_lavf_control"); CalIInstr->setCalledFunction(targetFunc); ... "F" is the function containing the call. But it leads to the following error: ... Call parameter type does not match function signature! %struct.demuxer* %0 %struct.demuxer.2657* %10 = tail call i32 @demux_lavf_control(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7, !dbg !863222 LLVM ERROR: Broken function found, compilation aborted! ... The [names:types] of call operands before the change is: ... [:%struct.demuxer*] [:i32] [:i8*] [:i32 (%struct.demuxer*, i32, i8*)*] ... And after the change is: ... [:%struct.demuxer*] [:i32] [:i8*] [demux_lavf_control:i32 (%struct.demuxer.2657*, i32, i8*)*] ... How can I solve the problem? Thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180816/682c39b6/attachment.html>
Ahmad Nouralizadeh Khorrami via llvm-dev
2018-Aug-17 11:30 UTC
[llvm-dev] Convert Function Pointer Call to Function Call at the IR Level
Hi. It seems that `struct.demuxer.2657*` is different from `struct.demuxer*`. Should I add something like a `bitcast` before the call? Thanks! On 16 August 2018 at 15:45, Ahmad Nouralizadeh Khorrami < ahmad.llvm at gmail.com> wrote:> Hi, > I want to convert a function pointer call in the IR of MPlayer to a > function call. For example, I have the following line: > ... > %10 = tail call i32 %7(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7, > !dbg !863222 > ... > I want to set the target which is stored in %7 to a real function called > "demux_lavf_control()" with the following definition: > ... > define internal i32 @demux_lavf_control(%struct.demuxer.2657* nocapture > readonly, i32, i8* nocapture) #0 !dbg !963916 { > ... > I wrote a function pass and found the mentioned function pointer call > (here, stored in "CallInstr") and set the call target as follows: > ... > Module *theModule = F.getParent(); > Function *targetFunc = theModule->getFunction("demux_lavf_control"); > CalIInstr->setCalledFunction(targetFunc); > ... > "F" is the function containing the call. But it leads to the following > error: > ... > Call parameter type does not match function signature! > %struct.demuxer* %0 > %struct.demuxer.2657* %10 = tail call i32 @demux_lavf_control(%struct.demuxer* > nonnull %0, i32 %1, i8* %2) #7, !dbg !863222 > LLVM ERROR: Broken function found, compilation aborted! > ... > The [names:types] of call operands before the change is: > ... > [:%struct.demuxer*] > [:i32] > [:i8*] > [:i32 (%struct.demuxer*, i32, i8*)*] > ... > And after the change is: > ... > [:%struct.demuxer*] > [:i32] > [:i8*] > [demux_lavf_control:i32 (%struct.demuxer.2657*, i32, i8*)*] > ... > How can I solve the problem? > Thanks in advance! >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180817/6f5f38dd/attachment.html>
mayuyu.io via llvm-dev
2018-Aug-18 07:26 UTC
[llvm-dev] Convert Function Pointer Call to Function Call at the IR Level
Yep. We encountered similar issue a while ago due to IR linking. A bitcasted function argument would do Zhang> 在 2018年8月17日,19:30,Ahmad Nouralizadeh Khorrami via llvm-dev <llvm-dev at lists.llvm.org> 写道: > > Hi. > It seems that `struct.demuxer.2657*` is different from `struct.demuxer*`. Should I add something like a `bitcast` before the call? > Thanks! > >> On 16 August 2018 at 15:45, Ahmad Nouralizadeh Khorrami <ahmad.llvm at gmail.com> wrote: >> Hi, >> I want to convert a function pointer call in the IR of MPlayer to a function call. For example, I have the following line: >> ... >> %10 = tail call i32 %7(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7, !dbg !863222 >> ... >> I want to set the target which is stored in %7 to a real function called "demux_lavf_control()" with the following definition: >> ... >> define internal i32 @demux_lavf_control(%struct.demuxer.2657* nocapture readonly, i32, i8* nocapture) #0 !dbg !963916 { >> ... >> I wrote a function pass and found the mentioned function pointer call (here, stored in "CallInstr") and set the call target as follows: >> ... >> Module *theModule = F.getParent(); >> Function *targetFunc = theModule->getFunction("demux_lavf_control"); >> CalIInstr->setCalledFunction(targetFunc); >> ... >> "F" is the function containing the call. But it leads to the following error: >> ... >> Call parameter type does not match function signature! >> %struct.demuxer* %0 >> %struct.demuxer.2657* %10 = tail call i32 @demux_lavf_control(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7, !dbg !863222 >> LLVM ERROR: Broken function found, compilation aborted! >> ... >> The [names:types] of call operands before the change is: >> ... >> [:%struct.demuxer*] >> [:i32] >> [:i8*] >> [:i32 (%struct.demuxer*, i32, i8*)*] >> ... >> And after the change is: >> ... >> [:%struct.demuxer*] >> [:i32] >> [:i8*] >> [demux_lavf_control:i32 (%struct.demuxer.2657*, i32, i8*)*] >> ... >> How can I solve the problem? >> Thanks in advance! > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180818/ad8d4c1c/attachment.html>