CIRCT  20.0.0git
CombDialect.cpp
Go to the documentation of this file.
1 //===- CombDialect.cpp - Implement the Comb dialect -----------------------===//
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 implements the Comb dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "circt/Dialect/HW/HWOps.h"
16 #include "mlir/IR/Builders.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/DialectImplementation.h"
19 
20 using namespace circt;
21 using namespace comb;
22 
23 //===----------------------------------------------------------------------===//
24 // Dialect specification.
25 //===----------------------------------------------------------------------===//
26 
27 void CombDialect::initialize() {
28  // Register operations.
29  addOperations<
30 #define GET_OP_LIST
31 #include "circt/Dialect/Comb/Comb.cpp.inc"
32  >();
33 }
34 
35 /// Registered hook to materialize a single constant operation from a given
36 /// attribute value with the desired resultant type. This method should use
37 /// the provided builder to create the operation without changing the
38 /// insertion position. The generated operation is expected to be constant
39 /// like, i.e. single result, zero operands, non side-effecting, etc. On
40 /// success, this hook should return the value generated to represent the
41 /// constant value. Otherwise, it should return null on failure.
42 Operation *CombDialect::materializeConstant(OpBuilder &builder, Attribute value,
43  Type type, Location loc) {
44  // Integer constants.
45  if (auto intType = dyn_cast<IntegerType>(type))
46  if (auto attrValue = dyn_cast<IntegerAttr>(value))
47  return builder.create<hw::ConstantOp>(loc, type, attrValue);
48 
49  // Parameter expressions materialize into hw.param.value.
50  auto parentOp = builder.getBlock()->getParentOp();
51  auto curModule = dyn_cast<hw::HWModuleOp>(parentOp);
52  if (!curModule)
53  curModule = parentOp->getParentOfType<hw::HWModuleOp>();
54  if (curModule && isValidParameterExpression(value, curModule))
55  return builder.create<hw::ParamValueOp>(loc, type, value);
56 
57  return nullptr;
58 }
59 
60 // Provide implementations for the enums we use.
61 #include "circt/Dialect/Comb/CombEnums.cpp.inc"
62 
63 #include "circt/Dialect/Comb/CombDialect.cpp.inc"
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
Definition: comb.py:1