190a8260cSergawy //===- TestModuleCombiner.cpp - Pass to test SPIR-V module combiner lib ---===//
290a8260cSergawy //
390a8260cSergawy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
490a8260cSergawy // See https://llvm.org/LICENSE.txt for license information.
590a8260cSergawy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
690a8260cSergawy //
790a8260cSergawy //===----------------------------------------------------------------------===//
890a8260cSergawy 
990a8260cSergawy #include "mlir/Dialect/SPIRV/ModuleCombiner.h"
1090a8260cSergawy 
1190a8260cSergawy #include "mlir/Dialect/SPIRV/SPIRVOps.h"
1290a8260cSergawy #include "mlir/Dialect/SPIRV/SPIRVTypes.h"
1390a8260cSergawy #include "mlir/IR/Builders.h"
14*65fcddffSRiver Riddle #include "mlir/IR/BuiltinOps.h"
1590a8260cSergawy #include "mlir/Pass/Pass.h"
1690a8260cSergawy 
1790a8260cSergawy using namespace mlir;
1890a8260cSergawy 
1990a8260cSergawy namespace {
2090a8260cSergawy class TestModuleCombinerPass
2190a8260cSergawy     : public PassWrapper<TestModuleCombinerPass,
2290a8260cSergawy                          OperationPass<mlir::ModuleOp>> {
2390a8260cSergawy public:
2490a8260cSergawy   TestModuleCombinerPass() = default;
2590a8260cSergawy   TestModuleCombinerPass(const TestModuleCombinerPass &) {}
2690a8260cSergawy   void runOnOperation() override;
2790a8260cSergawy 
2890a8260cSergawy private:
2990a8260cSergawy   mlir::spirv::OwningSPIRVModuleRef combinedModule;
3090a8260cSergawy };
3190a8260cSergawy } // namespace
3290a8260cSergawy 
3390a8260cSergawy void TestModuleCombinerPass::runOnOperation() {
3490a8260cSergawy   auto modules = llvm::to_vector<4>(getOperation().getOps<spirv::ModuleOp>());
3590a8260cSergawy 
3690a8260cSergawy   OpBuilder combinedModuleBuilder(modules[0]);
3790a8260cSergawy   combinedModule = spirv::combine(modules, combinedModuleBuilder, nullptr);
3890a8260cSergawy 
3990a8260cSergawy   for (spirv::ModuleOp module : modules)
4090a8260cSergawy     module.erase();
4190a8260cSergawy }
4290a8260cSergawy 
4390a8260cSergawy namespace mlir {
4490a8260cSergawy void registerTestSpirvModuleCombinerPass() {
4590a8260cSergawy   PassRegistration<TestModuleCombinerPass> registration(
4690a8260cSergawy       "test-spirv-module-combiner", "Tests SPIR-V module combiner library");
4790a8260cSergawy }
4890a8260cSergawy } // namespace mlir
49