[TableGen] Avoid repeated map lookups (NFC) (#126381)
[llvm-project.git] / mlir / test / lib / Analysis / TestMemRefBoundCheck.cpp
bloba036ae836c3cbbf4d8e90f7cb8438e4d5d86bcea
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.
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"
25 using namespace mlir;
26 using namespace mlir::affine;
28 namespace {
30 /// Checks for out of bound memref access subscripts..
31 struct TestMemRefBoundCheck
32 : public PassWrapper<TestMemRefBoundCheck, OperationPass<>> {
33 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefBoundCheck)
35 StringRef getArgument() const final { return "test-memref-bound-check"; }
36 StringRef getDescription() const final {
37 return "Check memref access bounds";
39 void runOnOperation() override;
42 } // namespace
44 void TestMemRefBoundCheck::runOnOperation() {
45 getOperation()->walk([](Operation *opInst) {
46 TypeSwitch<Operation *>(opInst)
47 .Case<AffineReadOpInterface, AffineWriteOpInterface>(
48 [](auto op) { (void)boundCheckLoadOrStoreOp(op); });
50 // TODO: do this for DMA ops as well.
51 });
54 namespace mlir {
55 namespace test {
56 void registerMemRefBoundCheck() { PassRegistration<TestMemRefBoundCheck>(); }
57 } // namespace test
58 } // namespace mlir