From bbd10b4579ef13707e97a06e7c7b981600f9d9e1 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 17 May 2016 14:45:30 +0000 Subject: [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 --- llvm/lib/Support/Path.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'llvm/lib/Support') diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index f9a71b986a8..406a37b2cc0 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -522,6 +522,29 @@ void replace_extension(SmallVectorImpl &path, const Twine &extension) { path.append(ext.begin(), ext.end()); } +void replace_path_prefix(SmallVectorImpl &Path, + const StringRef &OldPrefix, + const StringRef &NewPrefix) { + if (OldPrefix.empty() && NewPrefix.empty()) + return; + + StringRef OrigPath(Path.begin(), Path.size()); + if (!OrigPath.startswith(OldPrefix)) + return; + + // If prefixes have the same size we can simply copy the new one over. + if (OldPrefix.size() == NewPrefix.size()) { + std::copy(NewPrefix.begin(), NewPrefix.end(), Path.begin()); + return; + } + + StringRef RelPath = OrigPath.substr(OldPrefix.size()); + SmallString<256> NewPath; + path::append(NewPath, NewPrefix); + path::append(NewPath, RelPath); + Path.swap(NewPath); +} + void native(const Twine &path, SmallVectorImpl &result) { assert((!path.isSingleStringRef() || path.getSingleStringRef().data() != result.data()) && -- cgit v1.2.3