Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/PassInstrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class PassInstrumentationCallbacks {

/// Add a class name to pass name mapping for use by pass instrumentation.
LLVM_ABI void addClassToPassName(StringRef ClassName, StringRef PassName);
/// Get the pass name for a given pass class name.
/// Get the pass name for a given pass class name. Empty if no match found.
LLVM_ABI StringRef getPassNameForClassName(StringRef ClassName);

private:
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/IR/PassInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Loop *>;

void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName,
StringRef PassName) {
assert(!PassName.empty() && "PassName can't be empty!");
ClassToPassName.try_emplace(ClassName, PassName.str());
}

Expand All @@ -33,7 +34,10 @@ PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) {
Fn();
ClassToPassNameCallbacks.clear();
}
return ClassToPassName[ClassName];
auto PassNameIter = ClassToPassName.find(ClassName);
if (PassNameIter != ClassToPassName.end())
return PassNameIter->second;
return {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {};
return "";

is a bit clearer, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't StringRef() different from StringRef("")? They'd compare the same, but go through different constructors (no need to check and store the string literal). Not that it'd matter, but at least in other places {} is used so I'd go for consistency.

}

AnalysisKey PassInstrumentationAnalysis::Key;
Expand Down