llvm-poolalloc DSA patch: code cleanups and thread safety

Hello,

I have a patch to DSA you may be interested in. I thought I’d post this to llvmdev so it will be archived and googeable in case others need it, even if you decide to not merge this into mainline :slight_smile: Here are the highlights:

  • I refactored StdLibDataStructures::processFunction into processFunction and processCallSite to remove a lot of copy/pasted code. I also moved the libAction table from StdLibPass.cpp to a new module, StdLibInfo.cpp, so it can be reused elsewhere.

  • I brought back DSAA, because I need it :slight_smile: Most importantly, I revised DSAA to make it is thread-safe. This involved:
    (a) special-casing pthread_create (see changes in StdLibInfo.cpp and StdLibPass.cpp)
    (b) adding a thread-escape analysis
    (c) checking for memory barriers in getModRefInfo(CS, Loc): if CS.getCalledFunction() is a memory barrier (such as pthread_mutex_lock) or invokes one transitively, and if Loc is not a thread-local Location (i.e., if it may escape the thread), then getModRefInfo() must return ModRef

  • I brought back SteensgaardDataStructures, which was needed for the thread-escape analysis in DSAA.

Attached is a patch, llvm-poollalloc.diff, which was generated against the latest svn revision, 137611. The patch compiles and tests against LLVM 2.9. (The project I need DSAA for requires LLVM 2.9. I believe it will compile against LLVM 3.0 if you remove all the s/Type/const Type/ lines in the patch, but I haven’t had a chance to verify this.)

Also attached are two diffs showing the changes to Steensgaard.cpp and DataStuctureAA.cpp compared to the version of those files I resurrected from svn. Finally, I also attached a simple example program, break-dsa.c, which compiles incorrectly with the old DSAA when optimized with -ds-aa -gvn. This illustrates the need for thread-safety checks.

Thanks,
-Tom

llvm-poolalloc.diff (134 KB)

DataStructureAA.cpp.diff (29.9 KB)

Steensgaard.cpp.diff (13.9 KB)

break-dsa.c (402 Bytes)