Changeset View
Changeset View
Standalone View
Standalone View
mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
//====- LowerToLLVM.cpp - Lowering from Toy+Affine+Std to LLVM ------------===// | //====- LowerToLLVM.cpp - Lowering from Toy+Affine+Std to LLVM ------------===// | ||||
Lint: Lint: clang-format-diff not found in user's PATH; not linting file. | |||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
} // end anonymous namespace | } // end anonymous namespace | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// ToyToLLVMLoweringPass | // ToyToLLVMLoweringPass | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
namespace { | namespace { | ||||
struct ToyToLLVMLoweringPass : public ModulePass<ToyToLLVMLoweringPass> { | struct ToyToLLVMLoweringPass | ||||
void runOnModule() final; | : public OperationPass<ToyToLLVMLoweringPass, ModuleOp> { | ||||
void runOnOperation() final; | |||||
}; | }; | ||||
} // end anonymous namespace | } // end anonymous namespace | ||||
void ToyToLLVMLoweringPass::runOnModule() { | void ToyToLLVMLoweringPass::runOnOperation() { | ||||
// The first thing to define is the conversion target. This will define the | // The first thing to define is the conversion target. This will define the | ||||
// final target for this lowering. For this lowering, we are only targeting | // final target for this lowering. For this lowering, we are only targeting | ||||
// the LLVM dialect. | // the LLVM dialect. | ||||
LLVMConversionTarget target(getContext()); | LLVMConversionTarget target(getContext()); | ||||
target.addLegalOp<ModuleOp, ModuleTerminatorOp>(); | target.addLegalOp<ModuleOp, ModuleTerminatorOp>(); | ||||
// During this lowering, we will also be lowering the MemRef types, that are | // During this lowering, we will also be lowering the MemRef types, that are | ||||
// currently being operated on, to a representation in LLVM. Do perform this | // currently being operated on, to a representation in LLVM. Do perform this | ||||
Show All 16 Lines | void ToyToLLVMLoweringPass::runOnOperation() { | ||||
populateStdToLLVMConversionPatterns(typeConverter, patterns); | populateStdToLLVMConversionPatterns(typeConverter, patterns); | ||||
// The only remaining operation to lower from the `toy` dialect, is the | // The only remaining operation to lower from the `toy` dialect, is the | ||||
// PrintOp. | // PrintOp. | ||||
patterns.insert<PrintOpLowering>(&getContext()); | patterns.insert<PrintOpLowering>(&getContext()); | ||||
// We want to completely lower to LLVM, so we use a `FullConversion`. This | // We want to completely lower to LLVM, so we use a `FullConversion`. This | ||||
// ensures that only legal operations will remain after the conversion. | // ensures that only legal operations will remain after the conversion. | ||||
auto module = getModule(); | auto module = getOperation(); | ||||
if (failed(applyFullConversion(module, target, patterns, &typeConverter))) | if (failed(applyFullConversion(module, target, patterns, &typeConverter))) | ||||
signalPassFailure(); | signalPassFailure(); | ||||
} | } | ||||
/// Create a pass for lowering operations the remaining `Toy` operations, as | /// Create a pass for lowering operations the remaining `Toy` operations, as | ||||
/// well as `Affine` and `Std`, to the LLVM dialect for codegen. | /// well as `Affine` and `Std`, to the LLVM dialect for codegen. | ||||
std::unique_ptr<mlir::Pass> mlir::toy::createLowerToLLVMPass() { | std::unique_ptr<mlir::Pass> mlir::toy::createLowerToLLVMPass() { | ||||
return std::make_unique<ToyToLLVMLoweringPass>(); | return std::make_unique<ToyToLLVMLoweringPass>(); | ||||
} | } |
clang-format-diff not found in user's PATH; not linting file.