diff --git a/mlir/include/mlir/CMakeLists.txt b/mlir/include/mlir/CMakeLists.txt --- a/mlir/include/mlir/CMakeLists.txt +++ b/mlir/include/mlir/CMakeLists.txt @@ -1,4 +1,3 @@ add_subdirectory(Dialect) add_subdirectory(IR) add_subdirectory(Interfaces) -add_subdirectory(Transforms) diff --git a/mlir/include/mlir/Dialect/AffineOps/AffineOps.h b/mlir/include/mlir/Dialect/AffineOps/AffineOps.h --- a/mlir/include/mlir/Dialect/AffineOps/AffineOps.h +++ b/mlir/include/mlir/Dialect/AffineOps/AffineOps.h @@ -19,8 +19,8 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" #include "mlir/IR/StandardTypes.h" +#include "mlir/Interfaces/LoopLikeInterface.h" #include "mlir/Interfaces/SideEffects.h" -#include "mlir/Transforms/LoopLikeInterface.h" namespace mlir { class AffineApplyOp; diff --git a/mlir/include/mlir/Dialect/AffineOps/AffineOps.td b/mlir/include/mlir/Dialect/AffineOps/AffineOps.td --- a/mlir/include/mlir/Dialect/AffineOps/AffineOps.td +++ b/mlir/include/mlir/Dialect/AffineOps/AffineOps.td @@ -14,8 +14,8 @@ #define AFFINE_OPS include "mlir/Dialect/AffineOps/AffineOpsBase.td" +include "mlir/Interfaces/LoopLikeInterface.td" include "mlir/Interfaces/SideEffects.td" -include "mlir/Transforms/LoopLikeInterface.td" def Affine_Dialect : Dialect { let name = "affine"; diff --git a/mlir/include/mlir/Dialect/LoopOps/LoopOps.h b/mlir/include/mlir/Dialect/LoopOps/LoopOps.h --- a/mlir/include/mlir/Dialect/LoopOps/LoopOps.h +++ b/mlir/include/mlir/Dialect/LoopOps/LoopOps.h @@ -17,8 +17,8 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/Interfaces/LoopLikeInterface.h" #include "mlir/Interfaces/SideEffects.h" -#include "mlir/Transforms/LoopLikeInterface.h" namespace mlir { namespace loop { diff --git a/mlir/include/mlir/Dialect/LoopOps/LoopOps.td b/mlir/include/mlir/Dialect/LoopOps/LoopOps.td --- a/mlir/include/mlir/Dialect/LoopOps/LoopOps.td +++ b/mlir/include/mlir/Dialect/LoopOps/LoopOps.td @@ -13,8 +13,8 @@ #ifndef LOOP_OPS #define LOOP_OPS +include "mlir/Interfaces/LoopLikeInterface.td" include "mlir/Interfaces/SideEffects.td" -include "mlir/Transforms/LoopLikeInterface.td" def Loop_Dialect : Dialect { let name = "loop"; diff --git a/mlir/include/mlir/Interfaces/CMakeLists.txt b/mlir/include/mlir/Interfaces/CMakeLists.txt --- a/mlir/include/mlir/Interfaces/CMakeLists.txt +++ b/mlir/include/mlir/Interfaces/CMakeLists.txt @@ -18,6 +18,11 @@ mlir_tablegen(InferTypeOpInterface.cpp.inc -gen-op-interface-defs) add_public_tablegen_target(MLIRInferTypeOpInterfaceIncGen) +set(LLVM_TARGET_DEFINITIONS LoopLikeInterface.td) +mlir_tablegen(LoopLikeInterface.h.inc -gen-op-interface-decls) +mlir_tablegen(LoopLikeInterface.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(MLIRLoopLikeInterfaceIncGen) + set(LLVM_TARGET_DEFINITIONS SideEffects.td) mlir_tablegen(SideEffectInterfaces.h.inc -gen-op-interface-decls) mlir_tablegen(SideEffectInterfaces.cpp.inc -gen-op-interface-defs) diff --git a/mlir/include/mlir/Transforms/LoopLikeInterface.h b/mlir/include/mlir/Interfaces/LoopLikeInterface.h rename from mlir/include/mlir/Transforms/LoopLikeInterface.h rename to mlir/include/mlir/Interfaces/LoopLikeInterface.h --- a/mlir/include/mlir/Transforms/LoopLikeInterface.h +++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.h @@ -10,17 +10,15 @@ // //===----------------------------------------------------------------------===// -#ifndef MLIR_TRANSFORMS_LOOPLIKEINTERFACE_H_ -#define MLIR_TRANSFORMS_LOOPLIKEINTERFACE_H_ +#ifndef MLIR_INTERFACES_LOOPLIKEINTERFACE_H_ +#define MLIR_INTERFACES_LOOPLIKEINTERFACE_H_ #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" -#include "llvm/ADT/ArrayRef.h" namespace mlir { -#include "mlir/Transforms/LoopLikeInterface.h.inc" +#include "mlir/Interfaces/LoopLikeInterface.h.inc" } // namespace mlir -#endif // MLIR_TRANSFORMS_LOOPLIKEINTERFACE_H_ +#endif // MLIR_INTERFACES_LOOPLIKEINTERFACE_H_ diff --git a/mlir/include/mlir/Transforms/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td rename from mlir/include/mlir/Transforms/LoopLikeInterface.td rename to mlir/include/mlir/Interfaces/LoopLikeInterface.td --- a/mlir/include/mlir/Transforms/LoopLikeInterface.td +++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// // -// Defines the interface for loop-like operations as used by LICM. +// Defines the interface for loop-like operations. // //===----------------------------------------------------------------------===// -#ifndef MLIR_LOOPLIKEINTERFACE -#define MLIR_LOOPLIKEINTERFACE +#ifndef MLIR_INTERFACES_LOOPLIKEINTERFACE +#define MLIR_INTERFACES_LOOPLIKEINTERFACE include "mlir/IR/OpBase.td" @@ -46,4 +46,4 @@ ]; } -#endif // MLIR_LOOPLIKEINTERFACE +#endif // MLIR_INTERFACES_LOOPLIKEINTERFACE diff --git a/mlir/include/mlir/Transforms/CMakeLists.txt b/mlir/include/mlir/Transforms/CMakeLists.txt deleted file mode 100644 --- a/mlir/include/mlir/Transforms/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS LoopLikeInterface.td) -mlir_tablegen(LoopLikeInterface.h.inc -gen-op-interface-decls) -mlir_tablegen(LoopLikeInterface.cpp.inc -gen-op-interface-defs) -add_public_tablegen_target(MLIRLoopLikeInterfaceIncGen) - - diff --git a/mlir/lib/Dialect/AffineOps/CMakeLists.txt b/mlir/lib/Dialect/AffineOps/CMakeLists.txt --- a/mlir/lib/Dialect/AffineOps/CMakeLists.txt +++ b/mlir/lib/Dialect/AffineOps/CMakeLists.txt @@ -8,12 +8,12 @@ DEPENDS MLIRAffineOpsIncGen - MLIRLoopLikeInterfaceIncGen ) target_link_libraries(MLIRAffineOps PUBLIC MLIREDSC MLIRIR + MLIRLoopLikeInterface MLIRSideEffects MLIRStandardOps ) diff --git a/mlir/lib/Dialect/LoopOps/CMakeLists.txt b/mlir/lib/Dialect/LoopOps/CMakeLists.txt --- a/mlir/lib/Dialect/LoopOps/CMakeLists.txt +++ b/mlir/lib/Dialect/LoopOps/CMakeLists.txt @@ -7,13 +7,13 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/LoopOps DEPENDS - MLIRLoopLikeInterfaceIncGen MLIRLoopOpsIncGen ) target_link_libraries(MLIRLoopOps PUBLIC MLIREDSC MLIRIR + MLIRLoopLikeInterface MLIRSideEffects MLIRStandardOps LLVMSupport diff --git a/mlir/lib/Interfaces/CMakeLists.txt b/mlir/lib/Interfaces/CMakeLists.txt --- a/mlir/lib/Interfaces/CMakeLists.txt +++ b/mlir/lib/Interfaces/CMakeLists.txt @@ -3,6 +3,7 @@ ControlFlowInterfaces.cpp DerivedAttributeOpInterface.cpp InferTypeOpInterface.cpp + LoopLikeInterface.cpp SideEffects.cpp ) @@ -62,6 +63,20 @@ MLIRIR ) +add_llvm_library(MLIRLoopLikeInterface + LoopLikeInterface.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces + ) +add_dependencies(MLIRLoopLikeInterface + MLIRLoopLikeInterfaceIncGen + ) +target_link_libraries(MLIRLoopLikeInterface + PUBLIC + MLIRIR + ) + add_llvm_library(MLIRSideEffects SideEffects.cpp diff --git a/mlir/lib/Interfaces/LoopLikeInterface.cpp b/mlir/lib/Interfaces/LoopLikeInterface.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Interfaces/LoopLikeInterface.cpp @@ -0,0 +1,18 @@ +//===- LoopLikeInterface.cpp - Loop-like operations in MLIR ---------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "mlir/Interfaces/LoopLikeInterface.h" + +using namespace mlir; + +//===----------------------------------------------------------------------===// +// LoopLike Interfaces +//===----------------------------------------------------------------------===// + +/// Include the definitions of the loop-like interfaces. +#include "mlir/Interfaces/LoopLikeInterface.cpp.inc" diff --git a/mlir/lib/Transforms/CMakeLists.txt b/mlir/lib/Transforms/CMakeLists.txt --- a/mlir/lib/Transforms/CMakeLists.txt +++ b/mlir/lib/Transforms/CMakeLists.txt @@ -28,7 +28,6 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Transforms DEPENDS - MLIRLoopLikeInterfaceIncGen MLIRStandardOpsIncGen ) @@ -36,6 +35,7 @@ PUBLIC MLIRAffineOps MLIRAnalysis + MLIRLoopLikeInterface MLIRLoopOps MLIRPass MLIRTransformUtils diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp --- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp @@ -14,9 +14,9 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/Function.h" +#include "mlir/Interfaces/LoopLikeInterface.h" #include "mlir/Interfaces/SideEffects.h" #include "mlir/Pass/Pass.h" -#include "mlir/Transforms/LoopLikeInterface.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -26,12 +26,12 @@ using namespace mlir; namespace { - /// Loop invariant code motion (LICM) pass. struct LoopInvariantCodeMotion : public OperationPass { public: void runOnOperation() override; }; +} // end anonymous namespace // Checks whether the given op can be hoisted by checking that // - the op and any of its contained operations do not depend on SSA values @@ -107,8 +107,6 @@ return result; } -} // end anonymous namespace - void LoopInvariantCodeMotion::runOnOperation() { // Walk through all loops in a function in innermost-loop-first order. This // way, we first LICM from the inner loop, and place the ops in @@ -120,11 +118,6 @@ }); } -// Include the generated code for the loop-like interface here, as it otherwise -// has no compilation unit. This works as loop-invariant code motion is the -// only user of that interface. -#include "mlir/Transforms/LoopLikeInterface.cpp.inc" - std::unique_ptr mlir::createLoopInvariantCodeMotionPass() { return std::make_unique(); }