[LLVMdev] dominator, post-dominator and memory leak

Bin Tzeng bintzeng at gmail.com
Tue Nov 12 17:30:01 PST 2013


Hi all,

I have been writing a pass to heapify some alloca's (it is
pessimistization, not optimization). For example, in the following control
flow graph, there is a call to malloc inserted in block BB12. In order to
avoid memory leak, free's are needed. The free cannot be inserted in BB23
because BB23 is not dominated by BB12. There are two ways to go I can think
of here. One way is to insert a new basic block, say BB24, to connect both
BB21 and BB22 and a free can be inserted into the new block BB24. The new
block BB24 has to post-dominate BB12 and all the users of malloc have to
happen before BB24. Another way to go is to insert a free in both BB21 and
BB22. That is, a free is inserted in all the paths from BB12 to all exits
after all users of malloc to avoid memory leak. I wonder whether there is
any pass that does similar analysis in order to avoid duplication of
efforts.

               BB10 (entry)
              /       \
        BB11       BB12 (malloc)
       /               /      \
  BB13           /     BB15
      \             /         /       \
       \           /     BB18  BB19
        \         /           \       /
      BB20  BB21      BB22
             \      |         /
              \     |       /
               \    |     /
                \   |   /
                 BB23 (exit)

Any advice is appreciated. Thanks in advance!
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131112/95ca8ec8/attachment.html>


More information about the llvm-dev mailing list