[llvm] dc2b8ae - [LoopInfo] SFINAE mechanism for hoist into check

Christian Ulmann via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 23 23:25:01 PDT 2023


Author: Christian Ulmann
Date: 2023-04-24T06:21:17Z
New Revision: dc2b8ae962ffd6b8713877bbb6303e172ad982d6

URL: https://github.com/llvm/llvm-project/commit/dc2b8ae962ffd6b8713877bbb6303e172ad982d6
DIFF: https://github.com/llvm/llvm-project/commit/dc2b8ae962ffd6b8713877bbb6303e172ad982d6.diff

LOG: [LoopInfo] SFINAE mechanism for hoist into check

This commit introduces an SFINAE mechanism to make the LLVM hoist into
check member function not leak into the users of LoopInfo.

Depends on D148235

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D148504

Added: 
    

Modified: 
    llvm/include/llvm/Support/GenericLoopInfoImpl.h
    mlir/include/mlir/IR/Block.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index 59926f845ad3a..85233d38f0f6d 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -171,6 +171,22 @@ void LoopBase<BlockT, LoopT>::getExitEdges(
         ExitEdges.emplace_back(BB, Succ);
 }
 
+namespace detail {
+template <class BlockT>
+using has_hoist_check = decltype(&BlockT::isLegalToHoistInto);
+
+template <class BlockT>
+using detect_has_hoist_check = llvm::is_detected<has_hoist_check, BlockT>;
+
+/// SFINAE functions that dispatch to the isLegalToHoistInto member function or
+/// return false, if it doesn't exist.
+template <class BlockT> bool isLegalToHoistInto(BlockT *Block) {
+  if constexpr (detect_has_hoist_check<BlockT>::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 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader() const {
     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
index e8df98b1b5e6a..aadcca01c2cca 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -351,10 +351,6 @@ class Block : public IRObjectWithUseList<BlockOperand>,
   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.


        


More information about the llvm-commits mailing list