Skip to content

Commit 655cdf2

Browse files
authored
llvm-tli-checker: Remove TLINameList helper struct (#142535)
This avoids subclassing std::vector and a static constructor. This started as a refactor to make TargetLibraryInfo available during printing so a custom name could be reported. It turns out this struct wasn't doing anything, other than providing a hacky way of printing the standard name instead of the target's custom name. Just remove this and stop hacking on the TargetLibraryInfo to falsely report the function is available later.
1 parent 9086590 commit 655cdf2

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ class TargetLibraryInfo {
454454
return false;
455455
}
456456

457+
/// Return the canonical name for a LibFunc. This should not be used for
458+
/// semantic purposes, use getName instead.
459+
static StringRef getStandardName(LibFunc F) {
460+
return TargetLibraryInfoImpl::StandardNames[F];
461+
}
462+
457463
StringRef getName(LibFunc F) const {
458464
auto State = getState(F);
459465
if (State == TargetLibraryInfoImpl::Unavailable)

llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,43 +110,31 @@ static std::string getPrintableName(StringRef Name) {
110110
return OutputName;
111111
}
112112

113-
// Store all the names that TargetLibraryInfo knows about; the bool indicates
114-
// whether TLI has it marked as "available" for the target of interest.
115-
// This is a vector to preserve the sorted order for better reporting.
116-
struct TLINameList : std::vector<std::pair<StringRef, bool>> {
117-
// Record all the TLI info in the vector.
118-
void initialize(StringRef TargetTriple);
119-
// Print out what we found.
120-
void dump();
121-
};
122-
static TLINameList TLINames;
123-
124-
void TLINameList::initialize(StringRef TargetTriple) {
125-
Triple T(TargetTriple);
126-
TargetLibraryInfoImpl TLII(T);
127-
TargetLibraryInfo TLI(TLII);
113+
static void reportNumberOfEntries(const TargetLibraryInfo &TLI,
114+
StringRef TargetTriple) {
115+
unsigned NumAvailable = 0;
128116

129-
reserve(LibFunc::NumLibFuncs);
130-
size_t NumAvailable = 0;
117+
// Assume this gets called after initialize(), so we have the above line of
118+
// output as a header. So, for example, no need to repeat the triple.
131119
for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
132-
LibFunc LF = (LibFunc)FI;
133-
bool Available = TLI.has(LF);
134-
// getName returns names only for available funcs.
135-
TLII.setAvailable(LF);
136-
emplace_back(TLI.getName(LF), Available);
137-
if (Available)
120+
if (TLI.has(static_cast<LibFunc>(FI)))
138121
++NumAvailable;
139122
}
123+
140124
outs() << "TLI knows " << LibFunc::NumLibFuncs << " symbols, " << NumAvailable
141125
<< " available for '" << TargetTriple << "'\n";
142126
}
143127

144-
void TLINameList::dump() {
128+
static void dumpTLIEntries(const TargetLibraryInfo &TLI) {
145129
// Assume this gets called after initialize(), so we have the above line of
146130
// output as a header. So, for example, no need to repeat the triple.
147-
for (auto &TLIName : TLINames) {
148-
outs() << (TLIName.second ? " " : "not ")
149-
<< "available: " << getPrintableName(TLIName.first) << '\n';
131+
for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
132+
LibFunc LF = static_cast<LibFunc>(FI);
133+
bool IsAvailable = TLI.has(LF);
134+
StringRef FuncName = TargetLibraryInfo::getStandardName(LF);
135+
136+
outs() << (IsAvailable ? " " : "not ")
137+
<< "available: " << getPrintableName(FuncName) << '\n';
150138
}
151139
}
152140

@@ -271,11 +259,16 @@ int main(int argc, char *argv[]) {
271259
return 0;
272260
}
273261

274-
TLINames.initialize(Args.getLastArgValue(OPT_triple_EQ));
262+
StringRef TripleStr = Args.getLastArgValue(OPT_triple_EQ);
263+
Triple TargetTriple(TripleStr);
264+
TargetLibraryInfoImpl TLII(TargetTriple);
265+
TargetLibraryInfo TLI(TLII);
266+
267+
reportNumberOfEntries(TLI, TripleStr);
275268

276269
// --dump-tli doesn't require any input files.
277270
if (Args.hasArg(OPT_dump_tli)) {
278-
TLINames.dump();
271+
dumpTLIEntries(TLI);
279272
return 0;
280273
}
281274

@@ -321,9 +314,13 @@ int main(int argc, char *argv[]) {
321314
unsigned TLIdoesntSDKdoes = 0;
322315
unsigned TLIandSDKboth = 0;
323316
unsigned TLIandSDKneither = 0;
324-
for (auto &TLIName : TLINames) {
325-
bool TLIHas = TLIName.second;
326-
bool SDKHas = SDKNames.count(TLIName.first) == 1;
317+
318+
for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
319+
LibFunc LF = static_cast<LibFunc>(FI);
320+
321+
StringRef TLIName = TLI.getStandardName(LF);
322+
bool TLIHas = TLI.has(LF);
323+
bool SDKHas = SDKNames.count(TLIName) == 1;
327324
int Which = int(TLIHas) * 2 + int(SDKHas);
328325
switch (Which) {
329326
case 0: ++TLIandSDKneither; break;
@@ -338,8 +335,7 @@ int main(int argc, char *argv[]) {
338335
constexpr char YesNo[2][4] = {"no ", "yes"};
339336
constexpr char Indicator[4][3] = {"!!", ">>", "<<", "=="};
340337
outs() << Indicator[Which] << " TLI " << YesNo[TLIHas] << " SDK "
341-
<< YesNo[SDKHas] << ": " << getPrintableName(TLIName.first)
342-
<< '\n';
338+
<< YesNo[SDKHas] << ": " << getPrintableName(TLIName) << '\n';
343339
}
344340
}
345341

0 commit comments

Comments
 (0)