CIRCT  19.0.0git
CreateCompanionAssume.cpp
Go to the documentation of this file.
1 //===- CreateCompanionAssume.cpp - Create companion assume ----------------===//
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 defines the CreateCompanionAssume pass.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "PassDetails.h"
17 
18 using namespace circt;
19 using namespace firrtl;
20 
21 namespace {
22 struct CreateCompanionAssumePass
23  : public CreateCompanionAssumeBase<CreateCompanionAssumePass> {
24  void runOnOperation() override {
25  StringAttr emptyMessage = StringAttr::get(&getContext(), "");
26  getOperation().walk([&](firrtl::AssertOp assertOp) {
27  OpBuilder builder(assertOp);
28  builder.setInsertionPointAfter(assertOp);
29  auto guards = assertOp->getAttrOfType<ArrayAttr>("guards");
30  Operation *assume;
31  bool isUnrOnlyAssert = false;
32  // Regard the assertion as UNR only if "USE_UNR_ONLY_CONSTRAINTS" is
33  // included in the guards.
34  if (guards) {
35  isUnrOnlyAssert = llvm::any_of(guards, [](Attribute attr) {
36  StringAttr strAttr = dyn_cast<StringAttr>(attr);
37  return strAttr && strAttr.getValue() == "USE_UNR_ONLY_CONSTRAINTS";
38  });
39  }
40 
41  // TODO: Currently messages are dropped to preserve the old behaviour.
42  // Copy messages once we confirmed that it works well with UNR tools.
43  if (isUnrOnlyAssert)
44  // If UNROnly, use UnclockedAssumeIntrinsicOp.
45  assume = builder.create<firrtl::UnclockedAssumeIntrinsicOp>(
46  assertOp.getLoc(), assertOp.getPredicate(), assertOp.getEnable(),
47  emptyMessage, ValueRange{}, assertOp.getName());
48  else
49  // Otherwise use concurrent assume.
50  assume = builder.create<firrtl::AssumeOp>(
51  assertOp.getLoc(), assertOp.getClock(), assertOp.getPredicate(),
52  assertOp.getEnable(), emptyMessage, ValueRange{},
53  assertOp.getName(),
54  /*isConcurrent=*/true);
55 
56  // Add a guard "USE_PROPERTY_AS_CONSTRAINT" to companion assumes.
57  SmallVector<Attribute> newGuards{
58  builder.getStringAttr("USE_PROPERTY_AS_CONSTRAINT")};
59  if (guards)
60  newGuards.append(guards.begin(), guards.end());
61  assume->setAttr("guards", builder.getArrayAttr(newGuards));
62  });
63  }
64 };
65 
66 } // end anonymous namespace
67 
68 std::unique_ptr<mlir::Pass> circt::firrtl::createCreateCompanionAssume() {
69  return std::make_unique<CreateCompanionAssumePass>();
70 }
Builder builder
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
std::unique_ptr< mlir::Pass > createCreateCompanionAssume()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21