18
18
19
19
#include < string>
20
20
#include < vector>
21
+ #include < set>
21
22
22
23
#include " swift/AST/DiagnosticsFrontend.h"
23
24
#include " swift/Frontend/Frontend.h"
38
39
using namespace swift ;
39
40
using namespace llvm ::opt;
40
41
42
+ // Identifiers hash just like pointers.
43
+ template <> struct llvm ::DenseMapInfo<std::string> {
44
+ static std::string getEmptyKey () {
45
+ return swift::Identifier::getEmptyKey ().str ().str ();
46
+ }
47
+ static std::string getTombstoneKey () {
48
+ return swift::Identifier::getTombstoneKey ().str ().str ();
49
+ }
50
+ static unsigned getHashValue (std::string Val) {
51
+ std::hash<std::string> Hasher;
52
+ return Hasher (Val);
53
+ }
54
+ static bool isEqual (std::string LHS, std::string RHS) {
55
+ return LHS == RHS;
56
+ }
57
+ };
58
+
41
59
class AutolinkExtractInvocation {
42
60
private:
43
61
std::string MainExecutablePath;
@@ -112,7 +130,7 @@ class AutolinkExtractInvocation {
112
130
// / Return 'true' if there was an error, and 'false' otherwise.
113
131
static bool
114
132
extractLinkerFlagsFromObjectFile (const llvm::object::ObjectFile *ObjectFile,
115
- std::vector <std::string> &LinkerFlags,
133
+ llvm::SetVector <std::string> &LinkerFlags,
116
134
CompilerInstance &Instance) {
117
135
// Search for the section we hold autolink entries in
118
136
for (auto &Section : ObjectFile->sections ()) {
@@ -141,7 +159,7 @@ extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
141
159
SectionData->split (SplitFlags, llvm::StringRef (" \0 " , 1 ), -1 ,
142
160
/* KeepEmpty=*/ false );
143
161
for (const auto &Flag : SplitFlags)
144
- LinkerFlags.push_back (Flag.str ());
162
+ LinkerFlags.insert (Flag.str ());
145
163
}
146
164
}
147
165
return false ;
@@ -152,7 +170,7 @@ extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
152
170
// / 'true' if there was an error, and 'false' otherwise.
153
171
static bool
154
172
extractLinkerFlagsFromObjectFile (const llvm::object::WasmObjectFile *ObjectFile,
155
- std::vector <std::string> &LinkerFlags,
173
+ llvm::SetVector <std::string> &LinkerFlags,
156
174
CompilerInstance &Instance) {
157
175
// Search for the data segment we hold autolink entries in
158
176
for (const llvm::object::WasmSegment &Segment : ObjectFile->dataSegments ()) {
@@ -165,7 +183,7 @@ extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
165
183
SegmentData.split (SplitFlags, llvm::StringRef (" \0 " , 1 ), -1 ,
166
184
/* KeepEmpty=*/ false );
167
185
for (const auto &Flag : SplitFlags)
168
- LinkerFlags.push_back (Flag.str ());
186
+ LinkerFlags.insert (Flag.str ());
169
187
}
170
188
}
171
189
return false ;
@@ -178,7 +196,7 @@ extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
178
196
static bool extractLinkerFlags (const llvm::object::Binary *Bin,
179
197
CompilerInstance &Instance,
180
198
StringRef BinaryFileName,
181
- std::vector <std::string> &LinkerFlags) {
199
+ llvm::SetVector <std::string> &LinkerFlags) {
182
200
if (auto *ObjectFile = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Bin)) {
183
201
return extractLinkerFlagsFromObjectFile (ObjectFile, LinkerFlags, Instance);
184
202
} else if (auto *ObjectFile =
@@ -227,7 +245,7 @@ int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
227
245
return 1 ;
228
246
}
229
247
230
- std::vector <std::string> LinkerFlags;
248
+ llvm::SetVector <std::string> LinkerFlags;
231
249
232
250
// Extract the linker flags from the objects.
233
251
for (const auto &BinaryFileName : Invocation.getInputFilenames ()) {
0 commit comments