LLVM 17.0.0git
StringSaver.cpp
Go to the documentation of this file.
1//===-- StringSaver.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
10
11using namespace llvm;
12
14 char *P = Alloc.Allocate<char>(S.size() + 1);
15 if (!S.empty())
16 memcpy(P, S.data(), S.size());
17 P[S.size()] = '\0';
18 return StringRef(P, S.size());
19}
20
22 auto R = Unique.insert(S);
23 if (R.second) // cache miss, need to actually save the string
24 *R.first = Strings.save(S); // safe replacement with equal value
25 return *R.first;
26}
#define P(N)
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
StringRef save(const char *S)
Definition: StringSaver.h:30
StringRef save(const char *S)
Definition: StringSaver.h:52
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18