1 //===- TestAssert.cpp - Test cf.assert Lowering ----------------*- c++ -*-===// 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 integration testing of wide integer 10 // emulation patterns. Applies conversion patterns only to functions whose 11 // names start with a specified prefix. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h" 16 #include "mlir/Conversion/LLVMCommon/ConversionTarget.h" 17 #include "mlir/Conversion/LLVMCommon/TypeConverter.h" 18 #include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" 19 #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 20 #include "mlir/Pass/Pass.h" 21 #include "mlir/Transforms/DialectConversion.h" 22 23 using namespace mlir; 24 25 namespace { 26 struct TestAssertPass 27 : public PassWrapper<TestAssertPass, OperationPass<ModuleOp>> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID__anon18aae7aa0111::TestAssertPass28 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAssertPass) 29 30 void getDependentDialects(DialectRegistry ®istry) const override { 31 registry.insert<cf::ControlFlowDialect, LLVM::LLVMDialect>(); 32 } getArgument__anon18aae7aa0111::TestAssertPass33 StringRef getArgument() const final { return "test-cf-assert"; } getDescription__anon18aae7aa0111::TestAssertPass34 StringRef getDescription() const final { 35 return "Function pass to test cf.assert lowering to LLVM without abort"; 36 } 37 runOnOperation__anon18aae7aa0111::TestAssertPass38 void runOnOperation() override { 39 LLVMConversionTarget target(getContext()); 40 RewritePatternSet patterns(&getContext()); 41 42 LLVMTypeConverter converter(&getContext()); 43 mlir::cf::populateAssertToLLVMConversionPattern(converter, patterns, 44 /*abortOnFailure=*/false); 45 46 if (failed(applyPartialConversion(getOperation(), target, 47 std::move(patterns)))) 48 signalPassFailure(); 49 } 50 }; 51 } // namespace 52 53 namespace mlir::test { registerTestCfAssertPass()54void registerTestCfAssertPass() { PassRegistration<TestAssertPass>(); } 55 } // namespace mlir::test 56