Patch reviewed by Daniel Dunbar. It will be followed by additional cleanup patches. llvm-svn: 150664
llvm-svn: 134516