1 //===- TestMemRefBoundCheck.cpp - Test out of bound access checks ---------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements a pass to check memref accesses for out of bound
12 //===----------------------------------------------------------------------===//
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"
23 #define DEBUG_TYPE "memref-bound-check"
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
)
34 StringRef
getArgument() const final
{ return "test-memref-bound-check"; }
35 StringRef
getDescription() const final
{
36 return "Check memref access bounds";
38 void runOnOperation() override
;
43 void TestMemRefBoundCheck::runOnOperation() {
44 getOperation()->walk([](Operation
*opInst
) {
45 TypeSwitch
<Operation
*>(opInst
)
46 .Case
<AffineReadOpInterface
, AffineWriteOpInterface
>(
47 [](auto op
) { (void)boundCheckLoadOrStoreOp(op
); });
49 // TODO: do this for DMA ops as well.
55 void registerMemRefBoundCheck() { PassRegistration
<TestMemRefBoundCheck
>(); }