Mikael Lepistö
2013-Mar-11 11:32 UTC
[LLVMdev] Opt pass for collecting static memory allocations (allocas and globals) to one big memory area.
Hi, I'm doing llvm pass for OpenCL code which does some memory checking to verify that code does not access memory outside of the programs own statically allocated areas. To make dynamic check generation easier, I would like to collect all allocas and global variable definitions and create one big memory structure (for each global, local and private) containing all the allocated memory as contiguous form to be able to just to add checks to loads/sotres that address is inside that memory structure. Does anyone know if there already exist some pass which does something like this (collects static allocations) or should I write this from the scratch ? Does the idea sound reasonable at all ? Cheers, Mikael Lepistö -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130311/c5868a2f/attachment.html>
John Criswell
2013-Mar-11 19:00 UTC
[LLVMdev] Opt pass for collecting static memory allocations (allocas and globals) to one big memory area.
On 3/11/13 6:32 AM, Mikael Lepistö wrote:> Hi, > > I'm doing llvm pass for OpenCL code which does some memory checking to > verify that code does not access memory outside of the programs own > statically allocated areas.If you're looking to see if your program only accesses in-bounds memory, SAFECode and Address Sanitizer may be able to do this for you already. If you use SAFECode, I'd recommend hacking it to use complete checks. If you're wanting to know that a piece of code accesses only certain types of memory (e.g., globals and stack but not heap), then you either need to write something yourself or modify the aforementioned tools.> > To make dynamic check generation easier, I would like to collect all > allocas and global variable definitions and create one big memory > structure (for each global, local and private) containing all the > allocated memory as contiguous form to be able to just to add checks > to loads/sotres that address is inside that memory structure.No, I don't believe such a transform exists, but it should be pretty easy to write. Just be forewarned that you can't safely promote allocas to global variables when they're used in loops or in functions that can be called recursively. You must either check for these conditions or assume a priori that you code does not do these things. -- John T.> > Does anyone know if there already exist some pass which does something > like this (collects static allocations) or should I write this from > the scratch ? Does the idea sound reasonable at all ? > > Cheers, Mikael Lepistö > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130311/51b92872/attachment.html>
Mikael Lepistö
2013-Mar-12 06:59 UTC
[LLVMdev] Opt pass for collecting static memory allocations (allocas and globals) to one big memory area.
On Mon, Mar 11, 2013 at 9:00 PM, John Criswell <criswell at illinois.edu>wrote:> On 3/11/13 6:32 AM, Mikael Lepistö wrote: > > Hi, > > I'm doing llvm pass for OpenCL code which does some memory checking to > verify that code does not access memory outside of the programs own > statically allocated areas. > > > If you're looking to see if your program only accesses in-bounds memory, > SAFECode and Address Sanitizer may be able to do this for you already. If > you use SAFECode, I'd recommend hacking it to use complete checks. > > If you're wanting to know that a piece of code accesses only certain types > of memory (e.g., globals and stack but not heap), then you either need to > write something yourself or modify the aforementioned tools. >Actually this part I have already implemented. I will send some information about it here after I get the pass and the system properly documented. That should be done before July.> > To make dynamic check generation easier, I would like to collect all > allocas and global variable definitions and create one big memory structure > (for each global, local and private) containing all the allocated memory > as contiguous form to be able to just to add checks to loads/sotres that > address is inside that memory structure. > > > No, I don't believe such a transform exists, but it should be pretty easy > to write. Just be forewarned that you can't safely promote allocas to > global variables when they're used in loops or in functions that can be > called recursively. You must either check for these conditions or assume a > priori that you code does not do these things. > >OpenCL does not support recursion so it won't be a problem. Neither I can think of any cases where allocas would be generated to be inside of a loop. But to be on the safe side better to assert if there are any alloca outside of entry block. Thanks for the comments! - Mikael -- John T.> > > Does anyone know if there already exist some pass which does something > like this (collects static allocations) or should I write this from the > scratch ? Does the idea sound reasonable at all ? > > Cheers, Mikael Lepistö > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130312/cd445c74/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Opt pass for collecting static memory allocations (allocas and globals) to one big memory area.
- [LLVMdev] Installing tbgen with llvm by default.
- [LLVMdev] Installing tbgen with llvm by default.
- [LLVMdev] Installing tbgen with llvm by default.
- [LLVMdev] Adding custom operation intrinsic for ASIP architectures.