|
| 1 | +//===- HoistEnzymeRegions.cpp -LICM for enzyme.autodiff_region ----------=== // |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This file implements passes to hoist computations within autodiff_region ops |
| 10 | +// to the caller |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include "Dialect/Ops.h" |
| 15 | +#include "Interfaces/AutoDiffOpInterface.h" |
| 16 | +#include "Passes/Passes.h" |
| 17 | + |
| 18 | +#include "mlir/Dialect/Func/IR/FuncOps.h" |
| 19 | +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
| 20 | +#include "mlir/Interfaces/FunctionInterfaces.h" |
| 21 | +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" |
| 22 | +#include "mlir/Transforms/RegionUtils.h" |
| 23 | +#include "llvm/ADT/TypeSwitch.h" |
| 24 | + |
| 25 | +using namespace mlir; |
| 26 | + |
| 27 | +namespace mlir { |
| 28 | +namespace enzyme { |
| 29 | +#define GEN_PASS_DEF_HOISTENZYMEFROMREGIONPASS |
| 30 | +#include "Passes/Passes.h.inc" |
| 31 | +} // namespace enzyme |
| 32 | +} // namespace mlir |
| 33 | + |
| 34 | +namespace { |
| 35 | + |
| 36 | +struct HoistEnzymeAutoDiff : public OpRewritePattern<enzyme::AutoDiffRegionOp> { |
| 37 | + using OpRewritePattern<enzyme::AutoDiffRegionOp>::OpRewritePattern; |
| 38 | + LogicalResult matchAndRewrite(enzyme::AutoDiffRegionOp op, |
| 39 | + PatternRewriter &rewriter) const override { |
| 40 | + |
| 41 | + return success(); |
| 42 | + } |
| 43 | +}; |
| 44 | + |
| 45 | +struct HoistEnzymeFromRegion |
| 46 | + : public enzyme::impl::HoistEnzymeFromRegionPassBase< |
| 47 | + HoistEnzymeFromRegion> { |
| 48 | + void runOnOperation() override { |
| 49 | + RewritePatternSet patterns(&getContext()); |
| 50 | + patterns.add<HoistEnzymeAutoDiff>(&getContext()); |
| 51 | + GreedyRewriteConfig config; |
| 52 | + (void)applyPatternsGreedily(getOperation(), std::move(patterns), config); |
| 53 | + } |
| 54 | +}; |
| 55 | +} // namespace |
0 commit comments