CIRCT  19.0.0git
Lint.cpp
Go to the documentation of this file.
1 //===- Lint.cpp -------------------------------------------------*- C++ -*-===//
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 #include "PassDetails.h"
10 #include "mlir/IR/Threading.h"
11 #include "llvm/ADT/APSInt.h"
12 
13 using namespace mlir;
14 using namespace circt;
15 using namespace firrtl;
16 
17 namespace {
18 struct LintPass : public LintBase<LintPass> {
19  void runOnOperation() override {
20  auto fModule = getOperation();
21  auto walkResult = fModule.walk<WalkOrder::PreOrder>([&](Operation *op) {
22  if (isa<WhenOp>(op))
23  return WalkResult::skip();
24  if (isa<AssertOp, VerifAssertIntrinsicOp>(op))
25  if (checkAssert(op).failed())
26  return WalkResult::interrupt();
27 
28  return WalkResult::advance();
29  });
30  if (walkResult.wasInterrupted())
31  return signalPassFailure();
32 
33  markAllAnalysesPreserved();
34  };
35 
36  LogicalResult checkAssert(Operation *op) {
37  Value predicate;
38  if (auto a = dyn_cast<AssertOp>(op)) {
39  if (auto constant = a.getEnable().getDefiningOp<firrtl::ConstantOp>())
40  if (constant.getValue().isOne()) {
41  predicate = a.getPredicate();
42  }
43  } else if (auto a = dyn_cast<VerifAssertIntrinsicOp>(op))
44  predicate = a.getProperty();
45 
46  if (!predicate)
47  return success();
48  if (auto constant = predicate.getDefiningOp<firrtl::ConstantOp>())
49  if (constant.getValue().isZero())
50  return op->emitOpError(
51  "is guaranteed to fail simulation, as the predicate is "
52  "constant false")
53  .attachNote(constant.getLoc())
54  << "constant defined here";
55 
56  if (auto reset = predicate.getDefiningOp<firrtl::AsUIntPrimOp>())
57  if (firrtl::type_isa<ResetType, AsyncResetType>(
58  reset.getInput().getType()))
59  return op->emitOpError("is guaranteed to fail simulation, as the "
60  "predicate is a reset signal")
61  .attachNote(reset.getInput().getLoc())
62  << "reset signal defined here";
63 
64  return success();
65  }
66 };
67 } // namespace
68 
69 std::unique_ptr<Pass> firrtl::createLintingPass() {
70  return std::make_unique<LintPass>();
71 }
std::unique_ptr< mlir::Pass > createLintingPass()
Definition: Lint.cpp:69
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21