[Mlir-commits] [mlir] d8f3c50 - [mlir][Analysis] CFGLoopInfo instantiation in C++
Christian Ulmann
llvmlistbot at llvm.org
Fri Apr 14 04:23:28 PDT 2023
Author: Christian Ulmann
Date: 2023-04-14T11:22:22Z
New Revision: d8f3c50760ef6249e012de934a746ac2bf9749f9
URL: https://github.com/llvm/llvm-project/commit/d8f3c50760ef6249e012de934a746ac2bf9749f9
DIFF: https://github.com/llvm/llvm-project/commit/d8f3c50760ef6249e012de934a746ac2bf9749f9.diff
LOG: [mlir][Analysis] CFGLoopInfo instantiation in C++
This commit moves the CFGLoopInfo instantiation into the C++ file to
ensure that it is only compiled once. Instantiating the template
explicitly revealed two missing functions that this commit also adds.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D148219
Added:
Modified:
mlir/include/mlir/Analysis/CFGLoopInfo.h
mlir/include/mlir/IR/Block.h
mlir/lib/Analysis/CFGLoopInfo.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Analysis/CFGLoopInfo.h b/mlir/include/mlir/Analysis/CFGLoopInfo.h
index 4bbae77f75797..53cfd6b36db67 100644
--- a/mlir/include/mlir/Analysis/CFGLoopInfo.h
+++ b/mlir/include/mlir/Analysis/CFGLoopInfo.h
@@ -18,7 +18,17 @@
#include "mlir/IR/Dominance.h"
#include "mlir/IR/RegionGraphTraits.h"
#include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Analysis/LoopInfoImpl.h"
+
+namespace mlir {
+class CFGLoop;
+class CFGLoopInfo;
+} // namespace mlir
+
+namespace llvm {
+// Implementation in LLVM's LoopInfoImpl.h
+extern template class LoopBase<mlir::Block, mlir::CFGLoop>;
+extern template class LoopInfoBase<mlir::Block, mlir::CFGLoop>;
+} // namespace llvm
namespace mlir {
@@ -38,6 +48,9 @@ class CFGLoopInfo : public llvm::LoopInfoBase<mlir::Block, mlir::CFGLoop> {
public:
CFGLoopInfo(const llvm::DominatorTreeBase<mlir::Block, false> &domTree);
};
+
+raw_ostream &operator<<(raw_ostream &os, mlir::Block &block);
+
} // namespace mlir
#endif // MLIR_ANALYSIS_LOOPINFO_H
diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index aadcca01c2cca..e8df98b1b5e6a 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -351,6 +351,10 @@ 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.
diff --git a/mlir/lib/Analysis/CFGLoopInfo.cpp b/mlir/lib/Analysis/CFGLoopInfo.cpp
index 983643f97af53..637b3768289cd 100644
--- a/mlir/lib/Analysis/CFGLoopInfo.cpp
+++ b/mlir/lib/Analysis/CFGLoopInfo.cpp
@@ -7,6 +7,12 @@
//===----------------------------------------------------------------------===//
#include "mlir/Analysis/CFGLoopInfo.h"
+#include "llvm/Analysis/LoopInfoImpl.h"
+
+// Explicitly instantiate the LoopBase and LoopInfoBase classes defined in
+// LoopInfoImpl.h for CFGLoops
+template class llvm::LoopBase<mlir::Block, mlir::CFGLoop>;
+template class llvm::LoopInfoBase<mlir::Block, mlir::CFGLoop>;
using namespace mlir;
@@ -17,3 +23,8 @@ CFGLoopInfo::CFGLoopInfo(
const llvm::DominatorTreeBase<mlir::Block, false> &domTree) {
analyze(domTree);
}
+
+raw_ostream &mlir::operator<<(raw_ostream &os, mlir::Block &block) {
+ block.print(os);
+ return os;
+}
More information about the Mlir-commits
mailing list