Solution for memory leak in tblgen

wuhui1973 wuhui1973 at 163.com
Mon Jul 28 01:53:52 PDT 2014


Hello Hal, Andy, Nadav, Tom & all:


I have worked out a solution for the memory leak problem in tblgen. This memory leak problem is known and deliberatly left by the author for later fix.


My solution follows the author's suggestion - using reference counter to track the TreePatternNode & TreePattern objects.


Besides, though TreePatternNodes form DAGs, but with TreePattern, they can form cyclic graph, the solution also includes


a method to break the cyclic reference. The solution detail please refer to the attachment.


I have checked the solution with following actions:


1> Check tblgen running log, it looks like this:


     llvm[3]: Building X86.td register info implementation with tblgen
     llvm[3]: Building X86.td instruction information with tblgen
    1. NumTPNAlloc: 84347, NumTPNRel: 20190            <--- TPN: TreePatternNode
    1. NumTPAlloc: 13441, NumTPRel: 9215                  <--- TP: TreePattern
    2. NumTPNAlloc: 84347, NumTPNRel: 83879
    2. NumTPAlloc: 13441, NumTPRel: 13271
    468 TPNs remain, 170 TPs remain                            <--- These are cyclic referred nodes
    Release done
    3. NumTPNAlloc: 84347, NumTPNRel: 84347
    3. NumTPAlloc: 13441, NumTPRel: 13441


    Has confirmed all allocated objects get released during the loadbuild for all supported targets.


2> Compare the generated .inc file with those generated by sainty code. Has confirmed they all the same.


3> run "make check" to verify the generated llvm-programs, gets following result:
It contains one error, but the sainty code also gives the same result! I will raise the bug report later.
FAIL: LLVM :: ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s (6206 of 11281)
******************** TEST 'LLVM :: ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s' FAILED ********************
Script:
--
/sources/new/build_llvm/Debug+Asserts/bin/llvm-mc -triple=arm64-apple-ios7.0.0 -code-model=small -relocation-model=pic -filetype=obj -o /sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.o /sources/new/llvm/test/ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s
sed "s,<filename>,/sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.o,g" /sources/new/llvm/test/ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s > /sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.s
/sources/new/build_llvm/Debug+Asserts/bin/llvm-rtdyld -triple=arm64-apple-ios7.0.0 -verify -check=/sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.s /sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.o
--
Exit Code: 1


Command Output (stderr):
--
Expression 'decode_operand(adrp2, 1) = (stub_addr(/sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.o, __text, _ptr)[32:12] - adrp2[32:12])' is false: 0xfff00000 != 0x0
/sources/new/build_llvm/Debug+Asserts/bin/llvm-rtdyld: error: some checks in '/sources/new/build_llvm/test/ExecutionEngine/RuntimeDyld/AArch64/Output/foo.s' failed
--
********************
Testing Time: 3155.15s
********************
Failing Tests (1):
    LLVM :: ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s


  Expected Passes    : 11144
  Expected Failures  : 101
  Unsupported Tests  : 35
  Unexpected Failures: 1


So I think my solution is correct. Could you review it? Or help to forward to someone concerned? Thanks!


Regards
Hui Wu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DAGISelMatcherEmitter.cpp.patch
Type: application/octet-stream
Size: 509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DAGISelEmitter.cpp.patch
Type: application/octet-stream
Size: 1169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DAGISelMatcherGen.cpp.patch
Type: application/octet-stream
Size: 4672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TableGen.cpp.patch
Type: application/octet-stream
Size: 987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CodeGenDAGPatterns.h.patch
Type: application/octet-stream
Size: 27081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CodeGenDAGPatterns.cpp.patch
Type: application/octet-stream
Size: 61819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile.rules.patch
Type: application/octet-stream
Size: 621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment-0006.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: loadbuild.log
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/c33fa5d8/attachment.ksh>


More information about the llvm-commits mailing list