• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- TestModuleCombiner.cpp - Pass to test SPIR-V module combiner lib ---===//
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 #include "mlir/Dialect/SPIRV/ModuleCombiner.h"
10 
11 #include "mlir/Dialect/SPIRV/SPIRVOps.h"
12 #include "mlir/Dialect/SPIRV/SPIRVTypes.h"
13 #include "mlir/IR/Builders.h"
14 #include "mlir/IR/BuiltinOps.h"
15 #include "mlir/Pass/Pass.h"
16 
17 using namespace mlir;
18 
19 namespace {
20 class TestModuleCombinerPass
21     : public PassWrapper<TestModuleCombinerPass,
22                          OperationPass<mlir::ModuleOp>> {
23 public:
24   TestModuleCombinerPass() = default;
TestModuleCombinerPass(const TestModuleCombinerPass &)25   TestModuleCombinerPass(const TestModuleCombinerPass &) {}
26   void runOnOperation() override;
27 
28 private:
29   mlir::spirv::OwningSPIRVModuleRef combinedModule;
30 };
31 } // namespace
32 
runOnOperation()33 void TestModuleCombinerPass::runOnOperation() {
34   auto modules = llvm::to_vector<4>(getOperation().getOps<spirv::ModuleOp>());
35 
36   OpBuilder combinedModuleBuilder(modules[0]);
37   combinedModule = spirv::combine(modules, combinedModuleBuilder, nullptr);
38 
39   for (spirv::ModuleOp module : modules)
40     module.erase();
41 }
42 
43 namespace mlir {
registerTestSpirvModuleCombinerPass()44 void registerTestSpirvModuleCombinerPass() {
45   PassRegistration<TestModuleCombinerPass> registration(
46       "test-spirv-module-combiner", "Tests SPIR-V module combiner library");
47 }
48 } // namespace mlir
49