CIRCT  19.0.0git
ArcDialect.cpp
Go to the documentation of this file.
1 //===- ArcDialect.cpp - Arc dialect implementation ------------------------===//
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 
12 #include "circt/Dialect/HW/HWOps.h"
13 #include "mlir/Transforms/InliningUtils.h"
14 
15 using namespace circt;
16 using namespace arc;
17 
18 namespace {
19 /// This class defines the interface for handling inlining with Arc operations.
20 struct ArcInlinerInterface : public mlir::DialectInlinerInterface {
21  using mlir::DialectInlinerInterface::DialectInlinerInterface;
22 
23  bool isLegalToInline(Operation *call, Operation *callable,
24  bool wouldBeCloned) const override {
25  return isa<CallOp>(call);
26  }
27  bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
28  IRMapping &valueMapping) const override {
29  // TODO
30  return false;
31  }
32  bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned,
33  IRMapping &valueMapping) const override {
34  // TODO
35  return false;
36  }
37  void handleTerminator(Operation *op,
38  mlir::ValueRange valuesToRepl) const override {
39  assert(isa<arc::OutputOp>(op)); // arc does not have another terminator op
40  for (auto [from, to] : llvm::zip(valuesToRepl, op->getOperands()))
41  from.replaceAllUsesWith(to);
42  }
43 };
44 } // end anonymous namespace
45 
46 void ArcDialect::initialize() {
47  registerTypes();
48  addOperations<
49 #define GET_OP_LIST
50 #include "circt/Dialect/Arc/Arc.cpp.inc"
51  >();
52 
53  // Register interface implementations.
54  addInterfaces<ArcInlinerInterface>();
55 }
56 
57 /// Registered hook to materialize a single constant operation from a given
58 /// attribute value with the desired resultant type. This method should use
59 /// the provided builder to create the operation without changing the
60 /// insertion position. The generated operation is expected to be constant
61 /// like, i.e. single result, zero operands, non side-effecting, etc. On
62 /// success, this hook should return the value generated to represent the
63 /// constant value. Otherwise, it should return null on failure.
64 Operation *ArcDialect::materializeConstant(OpBuilder &builder, Attribute value,
65  Type type, Location loc) {
66  // Integer constants.
67  if (auto intType = dyn_cast<IntegerType>(type))
68  if (auto attrValue = dyn_cast<IntegerAttr>(value))
69  return builder.create<hw::ConstantOp>(loc, type, attrValue);
70 
71  // Parameter expressions materialize into hw.param.value.
72  auto *parentOp = builder.getBlock()->getParentOp();
73  auto curModule = dyn_cast<hw::HWModuleOp>(parentOp);
74  if (!curModule)
75  curModule = parentOp->getParentOfType<hw::HWModuleOp>();
76  if (curModule && isValidParameterExpression(value, curModule))
77  return builder.create<hw::ParamValueOp>(loc, type, value);
78 
79  return nullptr;
80 }
81 
82 #include "circt/Dialect/Arc/ArcDialect.cpp.inc"
83 #include "circt/Dialect/Arc/ArcEnums.cpp.inc"
assert(baseType &&"element must be base type")
Builder builder
bool isValidParameterExpression(Attribute attr, Operation *module)
Return true if the specified attribute tree is made up of nodes that are valid in a parameter express...
Definition: HWOps.cpp:221
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21