|
| 1 | +//===------------------ TestSPIRVCPURunnerPipeline.cpp --------------------===// |
| 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 a pass for use by mlir-spirv-cpu-runner tests. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h" |
| 14 | +#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h" |
| 15 | +#include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h" |
| 16 | +#include "mlir/Dialect/Arith/IR/Arith.h" |
| 17 | +#include "mlir/Dialect/DLTI/DLTI.h" |
| 18 | +#include "mlir/Dialect/Func/IR/FuncOps.h" |
| 19 | +#include "mlir/Dialect/GPU/IR/GPUDialect.h" |
| 20 | +#include "mlir/Dialect/GPU/Transforms/Passes.h" |
| 21 | +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
| 22 | +#include "mlir/Dialect/MemRef/IR/MemRef.h" |
| 23 | +#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h" |
| 24 | +#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h" |
| 25 | +#include "mlir/Dialect/SPIRV/Transforms/Passes.h" |
| 26 | +#include "mlir/ExecutionEngine/JitRunner.h" |
| 27 | +#include "mlir/ExecutionEngine/OptUtils.h" |
| 28 | +#include "mlir/IR/BuiltinOps.h" |
| 29 | +#include "mlir/Pass/Pass.h" |
| 30 | +#include "mlir/Pass/PassManager.h" |
| 31 | + |
| 32 | +using namespace mlir; |
| 33 | + |
| 34 | +namespace { |
| 35 | + |
| 36 | +class TestSPIRVCPURunnerPipelinePass |
| 37 | + : public PassWrapper<TestSPIRVCPURunnerPipelinePass, |
| 38 | + OperationPass<ModuleOp>> { |
| 39 | +public: |
| 40 | + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSPIRVCPURunnerPipelinePass) |
| 41 | + |
| 42 | + StringRef getArgument() const final { |
| 43 | + return "test-spirv-cpu-runner-pipeline"; |
| 44 | + } |
| 45 | + StringRef getDescription() const final { |
| 46 | + return "Runs a series of passes for lowering SPIR-V-dialect MLIR to " |
| 47 | + "LLVM-dialect MLIR intended for mlir-spirv-cpu-runner."; |
| 48 | + } |
| 49 | + void getDependentDialects(DialectRegistry ®istry) const override { |
| 50 | + registry.insert<mlir::arith::ArithDialect, mlir::LLVM::LLVMDialect, |
| 51 | + mlir::gpu::GPUDialect, mlir::spirv::SPIRVDialect, |
| 52 | + mlir::func::FuncDialect, mlir::memref::MemRefDialect, |
| 53 | + mlir::DLTIDialect>(); |
| 54 | + } |
| 55 | + |
| 56 | + TestSPIRVCPURunnerPipelinePass() = default; |
| 57 | + TestSPIRVCPURunnerPipelinePass(const TestSPIRVCPURunnerPipelinePass &) {} |
| 58 | + |
| 59 | + void runOnOperation() override { |
| 60 | + ModuleOp module = getOperation(); |
| 61 | + |
| 62 | + PassManager passManager(module->getContext(), |
| 63 | + module->getName().getStringRef()); |
| 64 | + if (failed(applyPassManagerCLOptions(passManager))) |
| 65 | + return signalPassFailure(); |
| 66 | + passManager.addPass(createGpuKernelOutliningPass()); |
| 67 | + passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true)); |
| 68 | + |
| 69 | + OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>(); |
| 70 | + nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass()); |
| 71 | + nestedPM.addPass(spirv::createSPIRVUpdateVCEPass()); |
| 72 | + passManager.addPass(createLowerHostCodeToLLVMPass()); |
| 73 | + passManager.addPass(createConvertSPIRVToLLVMPass()); |
| 74 | + |
| 75 | + if (failed(runPipeline(passManager, module))) |
| 76 | + signalPassFailure(); |
| 77 | + } |
| 78 | +}; |
| 79 | +} // namespace |
| 80 | + |
| 81 | +namespace mlir { |
| 82 | +namespace test { |
| 83 | +void registerTestSPIRVCPURunnerPipelinePass() { |
| 84 | + PassRegistration<TestSPIRVCPURunnerPipelinePass>(); |
| 85 | +} |
| 86 | +} // namespace test |
| 87 | +} // namespace mlir |
0 commit comments