CIRCT  20.0.0git
ESIVerifyConnections.cpp
Go to the documentation of this file.
1 //===- ESIVerifyConnections.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 
11 
12 #include "mlir/IR/BuiltinTypes.h"
13 #include "mlir/Pass/Pass.h"
14 
15 namespace circt {
16 namespace esi {
17 #define GEN_PASS_DEF_VERIFYESICONNECTIONS
18 #include "circt/Dialect/ESI/ESIPasses.h.inc"
19 } // namespace esi
20 } // namespace circt
21 
22 using namespace circt;
23 using namespace circt::esi;
24 
25 namespace {
26 struct ESIVerifyConnectionsPass
27  : public impl::VerifyESIConnectionsBase<ESIVerifyConnectionsPass> {
28  void runOnOperation() override;
29 };
30 } // anonymous namespace
31 
32 void ESIVerifyConnectionsPass::runOnOperation() {
33  // Walk the tree and look for ops which produce ESI types. Check each one.
34  getOperation()->walk([this](Operation *op) {
35  for (const OpResult &v : op->getResults())
36  if (isa<ChannelBundleType>(v.getType())) {
37  if (v.hasOneUse())
38  continue;
39  mlir::InFlightDiagnostic error =
40  op->emitError("bundles must have exactly one use");
41  for (Operation *user : v.getUsers())
42  error.attachNote(user->getLoc()) << "bundle used here";
43  signalPassFailure();
44 
45  } else if (isa<ChannelType>(v.getType())) {
46  if (std::distance(v.getUses().begin(), v.getUses().end()) <= 1)
47  continue;
48  mlir::InFlightDiagnostic error =
49  op->emitError("channels must have at most one use");
50  for (Operation *user : v.getUsers())
51  error.attachNote(user->getLoc()) << "channel used here";
52  signalPassFailure();
53  }
54  });
55 }
56 
57 std::unique_ptr<OperationPass<>> circt::esi::createESIVerifyConnectionsPass() {
58  return std::make_unique<ESIVerifyConnectionsPass>();
59 }
std::unique_ptr< OperationPass<> > createESIVerifyConnectionsPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: esi.py:1