diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h --- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h +++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h @@ -171,6 +171,22 @@ ExitEdges.emplace_back(BB, Succ); } +namespace detail { +template +using has_hoist_check = decltype(&BlockT::isLegalToHoistInto); + +template +using detect_has_hoist_check = llvm::is_detected; + +/// SFINAE functions that dispatch to the isLegalToHoistInto member function or +/// return false, if it doesn't exist. +template bool isLegalToHoistInto(BlockT *Block) { + if constexpr (detect_has_hoist_check::value) + return Block->isLegalToHoistInto(); + return false; +} +} // namespace detail + /// getLoopPreheader - If there is a preheader for this loop, return it. A /// loop has a preheader if there is only one edge to the header of the loop /// from outside of the loop and it is legal to hoist instructions into the @@ -188,7 +204,7 @@ return nullptr; // Make sure we are allowed to hoist instructions into the predecessor. - if (!Out->isLegalToHoistInto()) + if (!detail::isLegalToHoistInto(Out)) return nullptr; // Make sure there is only one exit out of the preheader. diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h --- a/mlir/include/mlir/IR/Block.h +++ b/mlir/include/mlir/IR/Block.h @@ -351,10 +351,6 @@ void printAsOperand(raw_ostream &os, bool printType = true); void printAsOperand(raw_ostream &os, AsmState &state); - /// NOTE: Do not call this function, it is only used to be compatible with the - /// LLVM loop analysis machinery. - bool isLegalToHoistInto() const { return false; }; - private: /// Pair of the parent object that owns this block and a bit that signifies if /// the operations within this block have a valid ordering.