[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / TextAPI / Utils.cpp
blob6d85083e0b54c14ea278fa96b9117fc17d58d8dd
1 //===- Utils.cpp ----------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implements utility functions for TextAPI Darwin operations.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Utils.h"
15 using namespace llvm;
16 using namespace llvm::MachO;
18 void llvm::MachO::replace_extension(SmallVectorImpl<char> &Path,
19 const Twine &Extension) {
20 StringRef P(Path.begin(), Path.size());
21 auto ParentPath = sys::path::parent_path(P);
22 auto Filename = sys::path::filename(P);
24 if (!ParentPath.ends_with(Filename.str() + ".framework")) {
25 sys::path::replace_extension(Path, Extension);
26 return;
28 // Framework dylibs do not have a file extension, in those cases the new
29 // extension is appended. e.g. given Path: "Foo.framework/Foo" and Extension:
30 // "tbd", the result is "Foo.framework/Foo.tbd".
31 SmallString<8> Storage;
32 StringRef Ext = Extension.toStringRef(Storage);
34 // Append '.' if needed.
35 if (!Ext.empty() && Ext[0] != '.')
36 Path.push_back('.');
38 // Append extension.
39 Path.append(Ext.begin(), Ext.end());