CIRCT 24.0.0git
Loading...
Searching...
No Matches
SeqDialect.cpp
Go to the documentation of this file.
1//===- SeqDialect.cpp - Implement the Seq 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 Seq dialect.
10//
11//===----------------------------------------------------------------------===//
12
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/BuiltinTypes.h"
19#include "mlir/IR/DialectImplementation.h"
20
21using namespace circt;
22using namespace seq;
23
24namespace {
25struct SeqProbeTypeDialectInterface : public hw::ProbeTypeDialectInterface {
27
28 bool isValidProbeElementType(Type type) const override {
29 return isa<ClockType>(type);
30 }
31};
32} // namespace
33
34//===----------------------------------------------------------------------===//
35// Dialect specification.
36//===----------------------------------------------------------------------===//
37
38void SeqDialect::initialize() {
39 registerTypes();
40 registerAttributes();
41
42 // Register operations.
43 addOperations<
44#define GET_OP_LIST
45#include "circt/Dialect/Seq/Seq.cpp.inc"
46 >();
47
48 addInterfaces<SeqProbeTypeDialectInterface>();
49}
50
51/// Registered hook to materialize a single constant operation from a given
52/// attribute value with the desired resultant type. This method should use
53/// the provided builder to create the operation without changing the
54/// insertion position. The generated operation is expected to be constant
55/// like, i.e. single result, zero operands, non side-effecting, etc. On
56/// success, this hook should return the value generated to represent the
57/// constant value. Otherwise, it should return null on failure.
58Operation *SeqDialect::materializeConstant(OpBuilder &builder, Attribute value,
59 Type type, Location loc) {
60 // Integer constants.
61 if (auto intType = dyn_cast<IntegerType>(type))
62 if (auto attrValue = dyn_cast<IntegerAttr>(value))
63 return hw::ConstantOp::create(builder, loc, type, attrValue);
64
65 if (isa<ClockType>(type))
66 if (auto attrValue = dyn_cast<ClockConstAttr>(value))
67 return seq::ConstClockOp::create(builder, loc, attrValue);
68
69 return nullptr;
70}
71
72#include "circt/Dialect/Seq/SeqDialect.cpp.inc"
create(data_type, value)
Definition hw.py:433
bool isValidProbeElementType(mlir::Type type)
Return true if type is a valid probe payload.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition seq.py:1
Interface for dialects to classify their types as valid probe payloads.
Definition HWTypes.h:53
ProbeTypeDialectInterface(mlir::Dialect *dialect)
Definition HWTypes.h:54