Skip to content

Commit 1dcff82

Browse files
committed
[ORC-RT] Drop __orc_rt::string_view now that we have c++17.
b135650 enabled the use of c++17 features in LLVM, which means that we can drop the ORC runtime's placeholder string_view implemention in favor of std::string_view.
1 parent 87dc7d4 commit 1dcff82

File tree

7 files changed

+42
-178
lines changed

7 files changed

+42
-178
lines changed

compiler-rt/lib/orc/adt.h

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,71 +58,10 @@ template <typename T, std::size_t Extent = dynamic_extent> class span {
5858
size_type Size = 0;
5959
};
6060

61-
/// A substitue for std::string_view (and llvm::StringRef).
62-
/// FIXME: Remove in favor of std::string_view once we have c++17.
63-
class string_view {
64-
public:
65-
typedef char value_type;
66-
typedef char *pointer;
67-
typedef const char *const_pointer;
68-
typedef char &reference;
69-
typedef const char &const_reference;
70-
typedef std::size_t size_type;
71-
typedef std::ptrdiff_t difference_type;
72-
73-
typedef const_pointer const_iterator;
74-
typedef const_iterator iterator;
75-
76-
constexpr string_view() noexcept = default;
77-
constexpr string_view(const char *S, size_type Count)
78-
: Data(S), Size(Count) {}
79-
string_view(const char *S) : Data(S), Size(strlen(S)) {}
80-
string_view(const std::string &S) : Data(S.data()), Size(S.size()) {}
81-
82-
constexpr const_iterator begin() const noexcept { return Data; }
83-
constexpr const_iterator end() const noexcept { return Data + Size; }
84-
constexpr const_pointer data() const noexcept { return Data; }
85-
constexpr const_reference operator[](size_type idx) { return Data[idx]; }
86-
constexpr size_type size() const noexcept { return Size; }
87-
constexpr bool empty() const noexcept { return Size == 0; }
88-
89-
friend bool operator==(const string_view &LHS, const string_view &RHS) {
90-
if (LHS.Size != RHS.Size)
91-
return false;
92-
if (LHS.Data == RHS.Data)
93-
return true;
94-
for (size_t I = 0; I != LHS.Size; ++I)
95-
if (LHS.Data[I] != RHS.Data[I])
96-
return false;
97-
return true;
98-
}
99-
100-
friend bool operator!=(const string_view &LHS, const string_view &RHS) {
101-
return !(LHS == RHS);
102-
}
103-
104-
private:
105-
const char *Data = nullptr;
106-
size_type Size = 0;
107-
};
108-
109-
inline std::ostream &operator<<(std::ostream &OS, string_view S) {
61+
inline std::ostream &operator<<(std::ostream &OS, std::string_view S) {
11062
return OS.write(S.data(), S.size());
11163
}
11264

11365
} // end namespace __orc_rt
11466

115-
namespace std {
116-
// Make string_view hashable.
117-
// FIXME: This can be removed (along with the string_view class) when we move
118-
// to C++17.
119-
template <> struct hash<__orc_rt::string_view> {
120-
size_t operator()(const __orc_rt::string_view &S) const {
121-
std::string Tmp(S.data(), S.size());
122-
return hash<std::string>()(Tmp);
123-
}
124-
};
125-
126-
} // namespace std
127-
12867
#endif // ORC_RT_ADT_H

compiler-rt/lib/orc/elfnix_platform.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class ELFNixPlatformRuntimeState {
109109
Error deregisterObjectSections(ELFNixPerObjectSectionsToRegister POSR);
110110

111111
const char *dlerror();
112-
void *dlopen(string_view Name, int Mode);
112+
void *dlopen(std::string_view Name, int Mode);
113113
int dlclose(void *DSOHandle);
114-
void *dlsym(void *DSOHandle, string_view Symbol);
114+
void *dlsym(void *DSOHandle, std::string_view Symbol);
115115

116116
int registerAtExit(void (*F)(void *), void *Arg, void *DSOHandle);
117117
void runAtExits(void *DSOHandle);
@@ -124,18 +124,18 @@ class ELFNixPlatformRuntimeState {
124124

125125
private:
126126
PerJITDylibState *getJITDylibStateByHeaderAddr(void *DSOHandle);
127-
PerJITDylibState *getJITDylibStateByName(string_view Path);
127+
PerJITDylibState *getJITDylibStateByName(std::string_view Path);
128128
PerJITDylibState &
129129
getOrCreateJITDylibState(ELFNixJITDylibInitializers &MOJDIs);
130130

131131
Error registerThreadDataSection(span<const char> ThreadDataSection);
132132

133133
Expected<ExecutorAddr> lookupSymbolInJITDylib(void *DSOHandle,
134-
string_view Symbol);
134+
std::string_view Symbol);
135135

136136
Expected<ELFNixJITDylibInitializerSequence>
137-
getJITDylibInitializersByName(string_view Path);
138-
Expected<void *> dlopenInitialize(string_view Path, int Mode);
137+
getJITDylibInitializersByName(std::string_view Path);
138+
Expected<void *> dlopenInitialize(std::string_view Path, int Mode);
139139
Error initializeJITDylib(ELFNixJITDylibInitializers &MOJDIs);
140140

141141
static ELFNixPlatformRuntimeState *MOPS;
@@ -196,7 +196,7 @@ Error ELFNixPlatformRuntimeState::deregisterObjectSections(
196196

197197
const char *ELFNixPlatformRuntimeState::dlerror() { return DLFcnError.c_str(); }
198198

199-
void *ELFNixPlatformRuntimeState::dlopen(string_view Path, int Mode) {
199+
void *ELFNixPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
200200
std::lock_guard<std::recursive_mutex> Lock(JDStatesMutex);
201201

202202
// Use fast path if all JITDylibs are already loaded and don't require
@@ -222,7 +222,8 @@ int ELFNixPlatformRuntimeState::dlclose(void *DSOHandle) {
222222
return 0;
223223
}
224224

225-
void *ELFNixPlatformRuntimeState::dlsym(void *DSOHandle, string_view Symbol) {
225+
void *ELFNixPlatformRuntimeState::dlsym(void *DSOHandle,
226+
std::string_view Symbol) {
226227
auto Addr = lookupSymbolInJITDylib(DSOHandle, Symbol);
227228
if (!Addr) {
228229
DLFcnError = toString(Addr.takeError());
@@ -282,7 +283,7 @@ ELFNixPlatformRuntimeState::getJITDylibStateByHeaderAddr(void *DSOHandle) {
282283
}
283284

284285
ELFNixPlatformRuntimeState::PerJITDylibState *
285-
ELFNixPlatformRuntimeState::getJITDylibStateByName(string_view Name) {
286+
ELFNixPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) {
286287
// FIXME: Avoid creating string copy here.
287288
auto I = JDNameToHeader.find(std::string(Name.data(), Name.size()));
288289
if (I == JDNameToHeader.end())
@@ -328,7 +329,7 @@ Error ELFNixPlatformRuntimeState::registerThreadDataSection(
328329

329330
Expected<ExecutorAddr>
330331
ELFNixPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
331-
string_view Sym) {
332+
std::string_view Sym) {
332333
Expected<ExecutorAddr> Result((ExecutorAddr()));
333334
if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
334335
SPSExecutorAddr, SPSString)>::call(&__orc_rt_elfnix_symbol_lookup_tag,
@@ -340,7 +341,8 @@ ELFNixPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
340341
}
341342

342343
Expected<ELFNixJITDylibInitializerSequence>
343-
ELFNixPlatformRuntimeState::getJITDylibInitializersByName(string_view Path) {
344+
ELFNixPlatformRuntimeState::getJITDylibInitializersByName(
345+
std::string_view Path) {
344346
Expected<ELFNixJITDylibInitializerSequence> Result(
345347
(ELFNixJITDylibInitializerSequence()));
346348
std::string PathStr(Path.data(), Path.size());
@@ -352,8 +354,8 @@ ELFNixPlatformRuntimeState::getJITDylibInitializersByName(string_view Path) {
352354
return Result;
353355
}
354356

355-
Expected<void *> ELFNixPlatformRuntimeState::dlopenInitialize(string_view Path,
356-
int Mode) {
357+
Expected<void *>
358+
ELFNixPlatformRuntimeState::dlopenInitialize(std::string_view Path, int Mode) {
357359
// Either our JITDylib wasn't loaded, or it or one of its dependencies allows
358360
// reinitialization. We need to call in to the JIT to see if there's any new
359361
// work pending.

compiler-rt/lib/orc/macho_platform.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ class MachOPlatformRuntimeState {
174174
Error deregisterThreadDataSection(span<const char> ThreadDataSection);
175175
Error registerObjectPlatformSections(
176176
ExecutorAddr HeaderAddr,
177-
std::vector<std::pair<string_view, ExecutorAddrRange>> Secs);
177+
std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs);
178178
Error deregisterObjectPlatformSections(
179179
ExecutorAddr HeaderAddr,
180-
std::vector<std::pair<string_view, ExecutorAddrRange>> Secs);
180+
std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs);
181181

182182
const char *dlerror();
183-
void *dlopen(string_view Name, int Mode);
183+
void *dlopen(std::string_view Name, int Mode);
184184
int dlclose(void *DSOHandle);
185-
void *dlsym(void *DSOHandle, string_view Symbol);
185+
void *dlsym(void *DSOHandle, std::string_view Symbol);
186186

187187
int registerAtExit(void (*F)(void *), void *Arg, void *DSOHandle);
188188
void runAtExits(JITDylibState &JDS);
@@ -194,10 +194,10 @@ class MachOPlatformRuntimeState {
194194

195195
private:
196196
JITDylibState *getJITDylibStateByHeader(void *DSOHandle);
197-
JITDylibState *getJITDylibStateByName(string_view Path);
197+
JITDylibState *getJITDylibStateByName(std::string_view Path);
198198

199199
Expected<ExecutorAddr> lookupSymbolInJITDylib(void *DSOHandle,
200-
string_view Symbol);
200+
std::string_view Symbol);
201201

202202
static Error registerObjCSelectors(JITDylibState &JDS);
203203
static Error registerObjCClasses(JITDylibState &JDS);
@@ -206,7 +206,7 @@ class MachOPlatformRuntimeState {
206206
static Error registerSwift5Types(JITDylibState &JDS);
207207
static Error runModInits(JITDylibState &JDS);
208208

209-
Expected<void *> dlopenImpl(string_view Path, int Mode);
209+
Expected<void *> dlopenImpl(std::string_view Path, int Mode);
210210
Error dlopenFull(JITDylibState &JDS);
211211
Error dlopenInitialize(JITDylibState &JDS, MachOJITDylibDepInfoMap &DepInfo);
212212

@@ -220,7 +220,7 @@ class MachOPlatformRuntimeState {
220220

221221
std::recursive_mutex JDStatesMutex;
222222
std::unordered_map<void *, JITDylibState> JDStates;
223-
std::unordered_map<string_view, void *> JDNameToHeader;
223+
std::unordered_map<std::string_view, void *> JDNameToHeader;
224224

225225
std::mutex ThreadDataSectionsMutex;
226226
std::map<const char *, size_t> ThreadDataSections;
@@ -321,7 +321,7 @@ Error MachOPlatformRuntimeState::deregisterThreadDataSection(
321321

322322
Error MachOPlatformRuntimeState::registerObjectPlatformSections(
323323
ExecutorAddr HeaderAddr,
324-
std::vector<std::pair<string_view, ExecutorAddrRange>> Secs) {
324+
std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs) {
325325
ORC_RT_DEBUG({
326326
printdbg("MachOPlatform: Registering object sections for %p.\n",
327327
HeaderAddr.toPtr<void *>());
@@ -383,7 +383,7 @@ bool removeIfPresent(std::vector<span<T>> &V, ExecutorAddrRange R) {
383383

384384
Error MachOPlatformRuntimeState::deregisterObjectPlatformSections(
385385
ExecutorAddr HeaderAddr,
386-
std::vector<std::pair<string_view, ExecutorAddrRange>> Secs) {
386+
std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs) {
387387
// TODO: Make this more efficient? (maybe unnecessary if removal is rare?)
388388
// TODO: Add a JITDylib prepare-for-teardown operation that clears all
389389
// registered sections, causing this function to take the fast-path.
@@ -442,7 +442,7 @@ Error MachOPlatformRuntimeState::deregisterObjectPlatformSections(
442442

443443
const char *MachOPlatformRuntimeState::dlerror() { return DLFcnError.c_str(); }
444444

445-
void *MachOPlatformRuntimeState::dlopen(string_view Path, int Mode) {
445+
void *MachOPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
446446
ORC_RT_DEBUG({
447447
std::string S(Path.data(), Path.size());
448448
printdbg("MachOPlatform::dlopen(\"%s\")\n", S.c_str());
@@ -477,7 +477,8 @@ int MachOPlatformRuntimeState::dlclose(void *DSOHandle) {
477477
return 0;
478478
}
479479

480-
void *MachOPlatformRuntimeState::dlsym(void *DSOHandle, string_view Symbol) {
480+
void *MachOPlatformRuntimeState::dlsym(void *DSOHandle,
481+
std::string_view Symbol) {
481482
auto Addr = lookupSymbolInJITDylib(DSOHandle, Symbol);
482483
if (!Addr) {
483484
DLFcnError = toString(Addr.takeError());
@@ -548,7 +549,7 @@ MachOPlatformRuntimeState::getJITDylibStateByHeader(void *DSOHandle) {
548549
}
549550

550551
MachOPlatformRuntimeState::JITDylibState *
551-
MachOPlatformRuntimeState::getJITDylibStateByName(string_view Name) {
552+
MachOPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) {
552553
// FIXME: Avoid creating string once we have C++20.
553554
auto I = JDNameToHeader.find(std::string(Name.data(), Name.size()));
554555
if (I != JDNameToHeader.end())
@@ -558,7 +559,7 @@ MachOPlatformRuntimeState::getJITDylibStateByName(string_view Name) {
558559

559560
Expected<ExecutorAddr>
560561
MachOPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
561-
string_view Sym) {
562+
std::string_view Sym) {
562563
Expected<ExecutorAddr> Result((ExecutorAddr()));
563564
if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
564565
SPSExecutorAddr, SPSString)>::call(&__orc_rt_macho_symbol_lookup_tag,
@@ -710,7 +711,7 @@ Error MachOPlatformRuntimeState::runModInits(JITDylibState &JDS) {
710711
return Error::success();
711712
}
712713

713-
Expected<void *> MachOPlatformRuntimeState::dlopenImpl(string_view Path,
714+
Expected<void *> MachOPlatformRuntimeState::dlopenImpl(std::string_view Path,
714715
int Mode) {
715716
// Try to find JITDylib state by name.
716717
auto *JDS = getJITDylibStateByName(Path);
@@ -976,7 +977,8 @@ __orc_rt_macho_register_object_platform_sections(char *ArgData,
976977
SPSMachOObjectPlatformSectionsMap)>::
977978
handle(ArgData, ArgSize,
978979
[](ExecutorAddr HeaderAddr,
979-
std::vector<std::pair<string_view, ExecutorAddrRange>> &Secs) {
980+
std::vector<std::pair<std::string_view, ExecutorAddrRange>>
981+
&Secs) {
980982
return MachOPlatformRuntimeState::get()
981983
.registerObjectPlatformSections(HeaderAddr, std::move(Secs));
982984
})
@@ -990,7 +992,8 @@ __orc_rt_macho_deregister_object_platform_sections(char *ArgData,
990992
SPSMachOObjectPlatformSectionsMap)>::
991993
handle(ArgData, ArgSize,
992994
[](ExecutorAddr HeaderAddr,
993-
std::vector<std::pair<string_view, ExecutorAddrRange>> &Secs) {
995+
std::vector<std::pair<std::string_view, ExecutorAddrRange>>
996+
&Secs) {
994997
return MachOPlatformRuntimeState::get()
995998
.deregisterObjectPlatformSections(HeaderAddr,
996999
std::move(Secs));

compiler-rt/lib/orc/run_program_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ __orc_rt_run_program_wrapper(const char *ArgData, size_t ArgSize) {
2929
handle(ArgData, ArgSize,
3030
[](const std::string &JITDylibName,
3131
const std::string &EntrySymbolName,
32-
const std::vector<string_view> &Args) {
32+
const std::vector<std::string_view> &Args) {
3333
std::vector<std::unique_ptr<char[]>> ArgVStorage;
3434
ArgVStorage.reserve(Args.size());
3535
for (auto &Arg : Args) {

compiler-rt/lib/orc/simple_packed_serialization.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,20 +399,20 @@ class SPSSerializationTraits<SPSTuple<SPSTagT1, SPSTagT2>, std::pair<T1, T2>> {
399399
///
400400
/// Serialization is as for regular strings. Deserialization points directly
401401
/// into the blob.
402-
template <> class SPSSerializationTraits<SPSString, __orc_rt::string_view> {
402+
template <> class SPSSerializationTraits<SPSString, std::string_view> {
403403
public:
404-
static size_t size(const __orc_rt::string_view &S) {
404+
static size_t size(const std::string_view &S) {
405405
return SPSArgList<uint64_t>::size(static_cast<uint64_t>(S.size())) +
406406
S.size();
407407
}
408408

409-
static bool serialize(SPSOutputBuffer &OB, const __orc_rt::string_view &S) {
409+
static bool serialize(SPSOutputBuffer &OB, const std::string_view &S) {
410410
if (!SPSArgList<uint64_t>::serialize(OB, static_cast<uint64_t>(S.size())))
411411
return false;
412412
return OB.write(S.data(), S.size());
413413
}
414414

415-
static bool deserialize(SPSInputBuffer &IB, __orc_rt::string_view &S) {
415+
static bool deserialize(SPSInputBuffer &IB, std::string_view &S) {
416416
const char *Data = nullptr;
417417
uint64_t Size;
418418
if (!SPSArgList<uint64_t>::deserialize(IB, Size))

0 commit comments

Comments
 (0)