Krzysztof Parzyszek via llvm-dev
2018-May-29 13:20 UTC
[llvm-dev] LLVM Block is not the basic block
On 5/29/2018 7:59 AM, Muhui Jiang via llvm-dev wrote:> So the reason why basic blocks can contain function calls is because of > code inlining?Not really. Basic blocks are units of code in a context of a specific function. When execution reaches a function call, it will go outside of the current function for some time, but then it will return back to the instruction following the call. From the perspective of the function containing the call, the call is simply another (potentially complicated and long-running) instruction. Generally speaking, a basic block ends at instruction A, if the instruction following A is not guaranteed to execute after A has executed. From the point of view of a given function, a call to another function will return back to the caller, so logically there is no reason to terminate the basic block at a call. There are of course complications, like calls that can throw exceptions, or calls that don't return, but the general idea is that calls do return. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Muhui Jiang via llvm-dev
2018-May-29 13:49 UTC
[llvm-dev] LLVM Block is not the basic block
Hi Krzysztof I see and I agree with your explanation However, you know some start of art binary analysis tools like angr will accept LLVM's such kind of design. You know there are some non-return functions. Does LLVM consider this? Do you have any ideas if I want to create a block that cannot contain function calls with LLVM IR. Regards Muhui 2018-05-29 21:20 GMT+08:00 Krzysztof Parzyszek via llvm-dev < llvm-dev at lists.llvm.org>:> On 5/29/2018 7:59 AM, Muhui Jiang via llvm-dev wrote: > >> So the reason why basic blocks can contain function calls is because of >> code inlining? >> > > Not really. Basic blocks are units of code in a context of a specific > function. When execution reaches a function call, it will go outside of the > current function for some time, but then it will return back to the > instruction following the call. From the perspective of the function > containing the call, the call is simply another (potentially complicated > and long-running) instruction. > Generally speaking, a basic block ends at instruction A, if the > instruction following A is not guaranteed to execute after A has executed. > From the point of view of a given function, a call to another function will > return back to the caller, so logically there is no reason to terminate the > basic block at a call. There are of course complications, like calls that > can throw exceptions, or calls that don't return, but the general idea is > that calls do return. > > -Krzysztof > > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted > by The Linux Foundation > _______________________________________________ > 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/20180529/ec011e8b/attachment.html>
Krzysztof Parzyszek via llvm-dev
2018-May-29 14:03 UTC
[llvm-dev] LLVM Block is not the basic block
It doesn't seem that LLVM treats non-returning calls in any special way in the LLVM IR. You could probably write your own pass that splits basic blocks at each call, but there are optimizations that would merge the pieces back together. If you do the splitting at the right moment, it may work, but it really depends on your specific application. -Krzysztof On 5/29/2018 8:49 AM, Muhui Jiang wrote:> Hi Krzysztof > > I see and I agree with your explanation > > However, you know some start of art binary analysis tools like angr will > accept LLVM's such kind of design. You know there are some non-return > functions. Does LLVM consider this? Do you have any ideas if I want to > create a block that cannot contain function calls with LLVM IR. > > Regards > Muhui > > 2018-05-29 21:20 GMT+08:00 Krzysztof Parzyszek via llvm-dev > <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>>: > > On 5/29/2018 7:59 AM, Muhui Jiang via llvm-dev wrote: > > So the reason why basic blocks can contain function calls is > because of code inlining? > > > Not really. Basic blocks are units of code in a context of a > specific function. When execution reaches a function call, it will > go outside of the current function for some time, but then it will > return back to the instruction following the call. From the > perspective of the function containing the call, the call is simply > another (potentially complicated and long-running) instruction. > Generally speaking, a basic block ends at instruction A, if the > instruction following A is not guaranteed to execute after A has > executed. From the point of view of a given function, a call to > another function will return back to the caller, so logically there > is no reason to terminate the basic block at a call. There are of > course complications, like calls that can throw exceptions, or calls > that don't return, but the general idea is that calls do return. > > -Krzysztof > > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, > hosted by The Linux Foundation > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > >-- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation