Skip to content

Commit

Permalink
[mlir] Avoid repeated hash lookups (NFC) (llvm#107518)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata authored Sep 6, 2024
1 parent b8d6885 commit 56b2907
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,10 @@ void TransformDialect::addTypeIfNotRegistered() {
template <typename DataTy>
DataTy &TransformDialect::getOrCreateExtraData() {
TypeID typeID = TypeID::get<DataTy>();
auto it = extraData.find(typeID);
if (it != extraData.end())
return static_cast<DataTy &>(*it->getSecond());

auto emplaced =
extraData.try_emplace(typeID, std::make_unique<DataTy>(getContext()));
return static_cast<DataTy &>(*emplaced.first->getSecond());
auto [it, inserted] = extraData.try_emplace(typeID);
if (inserted)
it->getSecond() = std::make_unique<DataTy>(getContext());
return static_cast<DataTy &>(*it->getSecond());
}

/// A wrapper for transform dialect extensions that forces them to be
Expand Down

0 comments on commit 56b2907

Please sign in to comment.