mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 20:46:05 +00:00

Static op verification cannot detect cases where an op is valid at compile time but may be invalid at runtime. An example of such an op is `memref::ExpandShapeOp`. Invalid at compile time: `memref.expand_shape %m [[0, 1]] : memref<11xf32> into memref<2x5xf32>` Valid at compile time (because we do not know any better): `memref.expand_shape %m [[0, 1]] : memref<?xf32> into memref<?x5xf32>`. This op may or may not be valid at runtime depending on the runtime shape of `%m`. Invalid runtime ops such as the one above are hard to debug because they can crash the program execution at a seemingly unrelated position or (even worse) compute an invalid result without crashing. This revision adds a new op interface `RuntimeVerifiableOpInterface` that can be implemented by ops that provide additional runtime verification. Such runtime verification can be computationally expensive, so it is only generated on an opt-in basis by running `-generate-runtime-verification`. A simple runtime verifier for `memref::ExpandShapeOp` is provided as an example. Differential Revision: https://reviews.llvm.org/D138576
18 lines
610 B
C++
18 lines
610 B
C++
//===- RuntimeVerifiableOpInterface.cpp - Op Verification -----------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Interfaces/RuntimeVerifiableOpInterface.h"
|
|
|
|
namespace mlir {
|
|
class Location;
|
|
class OpBuilder;
|
|
} // namespace mlir
|
|
|
|
/// Include the definitions of the interface.
|
|
#include "mlir/Interfaces/RuntimeVerifiableOpInterface.cpp.inc"
|