2020-02-05 09:23:17 -08:00
|
|
|
//===- TestMemRefBoundCheck.cpp - Test out of bound access checks ---------===//
|
2018-10-30 17:43:06 -07:00
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-30 17:43:06 -07:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-10-30 17:43:06 -07:00
|
|
|
//
|
2019-10-20 00:11:03 -07:00
|
|
|
// This file implements a pass to check memref accesses for out of bound
|
2018-10-30 17:43:06 -07:00
|
|
|
// accesses.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "mlir/Analysis/AffineAnalysis.h"
|
2019-02-22 16:51:08 -08:00
|
|
|
#include "mlir/Analysis/AffineStructures.h"
|
2018-11-08 17:31:01 -08:00
|
|
|
#include "mlir/Analysis/Utils.h"
|
2020-03-20 14:18:47 -07:00
|
|
|
#include "mlir/Dialect/Affine/IR/AffineOps.h"
|
2020-02-21 11:54:49 -08:00
|
|
|
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
2018-10-30 17:43:06 -07:00
|
|
|
#include "mlir/IR/Builders.h"
|
2019-02-19 17:17:46 -08:00
|
|
|
#include "mlir/Pass/Pass.h"
|
2020-04-14 14:53:50 -07:00
|
|
|
#include "llvm/ADT/TypeSwitch.h"
|
2018-10-30 17:43:06 -07:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "memref-bound-check"
|
|
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/// Checks for out of bound memef access subscripts..
|
2020-04-07 13:56:16 -07:00
|
|
|
struct TestMemRefBoundCheck
|
|
|
|
|
: public PassWrapper<TestMemRefBoundCheck, FunctionPass> {
|
2019-02-28 14:50:42 -08:00
|
|
|
void runOnFunction() override;
|
2018-10-30 17:43:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
2020-02-05 09:23:17 -08:00
|
|
|
void TestMemRefBoundCheck::runOnFunction() {
|
2019-03-27 08:55:17 -07:00
|
|
|
getFunction().walk([](Operation *opInst) {
|
2019-12-17 14:57:07 -08:00
|
|
|
TypeSwitch<Operation *>(opInst).Case<AffineLoadOp, AffineStoreOp>(
|
|
|
|
|
[](auto op) { boundCheckLoadOrStoreOp(op); });
|
|
|
|
|
|
2019-02-04 16:24:44 -08:00
|
|
|
// TODO(bondhugula): do this for DMA ops as well.
|
|
|
|
|
});
|
2018-10-30 17:43:06 -07:00
|
|
|
}
|
2018-11-06 18:34:18 -08:00
|
|
|
|
2020-02-12 09:03:40 +00:00
|
|
|
namespace mlir {
|
|
|
|
|
void registerMemRefBoundCheck() {
|
|
|
|
|
PassRegistration<TestMemRefBoundCheck>(
|
|
|
|
|
"test-memref-bound-check", "Check memref access bounds in a Function");
|
|
|
|
|
}
|
|
|
|
|
} // namespace mlir
|