[ThinLTO] Option to control path of distributed backend files

Summary:
Add support to control where files for a distributed backend (the
individual index files and optional imports files) are created.

This is invoked with a new thinlto-prefix-replace option in the gold
plugin and llvm-lto. If specified, expects a string of the form
"oldprefix:newprefix", and instead of generating these files in the
same directory path as the corresponding bitcode file, will use a path
formed by replacing the bitcode file's path prefix matching oldprefix
with newprefix.

Also add a new replace_path_prefix helper to Path.h in libSupport.

Depends on D19636.

Reviewers: joker.eph

Subscribers: llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D19644

llvm-svn: 269771
diff --git a/llvm/test/ThinLTO/X86/prefix_replace.ll b/llvm/test/ThinLTO/X86/prefix_replace.ll
new file mode 100644
index 0000000..7ae7d35
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/prefix_replace.ll
@@ -0,0 +1,16 @@
+; Check that changing the output path via prefix-replace works
+; RUN: mkdir -p %T/oldpath
+; RUN: opt -module-summary %s -o %T/oldpath/prefix_replace.o
+; Ensure that there is no existing file at the new path, so we properly
+; test the creation of the new file there.
+; RUN: rm -f %T/newpath/prefix_replace.o.thinlto.bc
+
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %T/oldpath/prefix_replace.o
+; RUN: llvm-lto -thinlto-action=distributedindexes -thinlto-prefix-replace="%T/oldpath/:%T/newpath/" -thinlto-index %t.index.bc %T/oldpath/prefix_replace.o
+
+; RUN: ls %T/newpath/prefix_replace.o.thinlto.bc
+
+define void @f() {
+entry:
+  ret void
+}