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/Analysis/AffineAnalysis.h" 15 #include "mlir/Analysis/AffineStructures.h" 16 #include "mlir/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, FunctionPass> { 32 void runOnFunction() override; 33 }; 34 35 } // end anonymous namespace 36 37 void TestMemRefBoundCheck::runOnFunction() { 38 getFunction().walk([](Operation *opInst) { 39 TypeSwitch<Operation *>(opInst) 40 .Case<AffineReadOpInterface, AffineWriteOpInterface>( 41 [](auto op) { (void)boundCheckLoadOrStoreOp(op); }); 42 43 // TODO: do this for DMA ops as well. 44 }); 45 } 46 47 namespace mlir { 48 namespace test { 49 void registerMemRefBoundCheck() { 50 PassRegistration<TestMemRefBoundCheck>( 51 "test-memref-bound-check", "Check memref access bounds in a Function"); 52 } 53 } // namespace test 54 } // namespace mlir 55