Refactor some duplicated code into helper functions.

llvm-svn: 177242
2 files changed