59 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a pass to check memref accesses for out of bound10// 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 25using namespace mlir;26using namespace mlir::affine;27 28namespace {29 30/// Checks for out of bound memref access subscripts..31struct TestMemRefBoundCheck32 : public PassWrapper<TestMemRefBoundCheck, OperationPass<>> {33 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefBoundCheck)34 35 StringRef getArgument() const final { return "test-memref-bound-check"; }36 StringRef getDescription() const final {37 return "Check memref access bounds";38 }39 void runOnOperation() override;40};41 42} // namespace43 44void TestMemRefBoundCheck::runOnOperation() {45 getOperation()->walk([](Operation *opInst) {46 TypeSwitch<Operation *>(opInst)47 .Case<AffineReadOpInterface, AffineWriteOpInterface>(48 [](auto op) { (void)boundCheckLoadOrStoreOp(op); });49 50 // TODO: do this for DMA ops as well.51 });52}53 54namespace mlir {55namespace test {56void registerMemRefBoundCheck() { PassRegistration<TestMemRefBoundCheck>(); }57} // namespace test58} // namespace mlir59