All global variables that are not enclosed in a declare target region must be captured in the target region as local variables do. Currently, there is no support for declare target, so this patch adds support for capturing all the global variables used in a the target region.
This patch requires http://reviews.llvm.org/D12871.
Alexey, after rebasing this patch with the latest changes, I started having a regression related with how DSAStack->hasDirective works. In my understanding it requires that a valid scope exists in the stack, or alternatively that 2 or more entries exist in the stack. In some cases DSAStack->hasDirective was being called with only one entry causing the iterators in there not to work properly. The fix for that was adding DSAStack->getCurScope(). It seems to be a harmless change, but still wanted to make sure you agree with that.
Thanks!