1 //===- TestMemRefBoundCheck.cpp - Test out of bound access checks ---------===// 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 to check memref accesses for out of bound 10 // accesses. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h" 15 #include "mlir/Dialect/Affine/Analysis/AffineStructures.h" 16 #include "mlir/Dialect/Affine/Analysis/Utils.h" 17 #include "mlir/Dialect/Affine/IR/AffineOps.h" 18 #include "mlir/IR/Builders.h" 19 #include "mlir/Pass/Pass.h" 20 #include "llvm/ADT/TypeSwitch.h" 21 #include "llvm/Support/Debug.h" 22 23 #define DEBUG_TYPE "memref-bound-check" 24 25 using namespace mlir; 26 27 namespace { 28 29 /// Checks for out of bound memref access subscripts.. 30 struct TestMemRefBoundCheck 31 : public PassWrapper<TestMemRefBoundCheck, OperationPass<>> { 32 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefBoundCheck) 33 34 StringRef getArgument() const final { return "test-memref-bound-check"; } 35 StringRef getDescription() const final { 36 return "Check memref access bounds"; 37 } 38 void runOnOperation() override; 39 }; 40 41 } // namespace 42 43 void TestMemRefBoundCheck::runOnOperation() { 44 getOperation()->walk([](Operation *opInst) { 45 TypeSwitch<Operation *>(opInst) 46 .Case<AffineReadOpInterface, AffineWriteOpInterface>( 47 [](auto op) { (void)boundCheckLoadOrStoreOp(op); }); 48 49 // TODO: do this for DMA ops as well. 50 }); 51 } 52 53 namespace mlir { 54 namespace test { 55 void registerMemRefBoundCheck() { PassRegistration<TestMemRefBoundCheck>(); } 56 } // namespace test 57 } // namespace mlir 58